@vidispine/vdt-js 21.3.0 → 22.1.0-pre.1

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/dist/index.js CHANGED
@@ -2,2461 +2,1980 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _typeof(obj) {
6
- "@babel/helpers - typeof";
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
8
+ var parseFileSize = require('filesize');
9
+ var _typeof = require('@babel/runtime/helpers/typeof');
10
+ var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
11
+ var _createClass = require('@babel/runtime/helpers/createClass');
12
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
17
+ var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
18
+ var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
19
+ var parseFileSize__default = /*#__PURE__*/_interopDefaultLegacy(parseFileSize);
20
+ var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
21
+ var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
22
+ var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
23
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
24
+
25
+ function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
+
27
+ function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$8(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
28
 
8
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
9
- _typeof = function (obj) {
10
- return typeof obj;
11
- };
12
- } else {
13
- _typeof = function (obj) {
14
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
15
- };
16
- }
29
+ var parseKeyValuePairType = function parseKeyValuePairType() {
30
+ var keyValuePairType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
17
31
 
18
- return _typeof(obj);
19
- }
32
+ var keyValuePairTypeReducer = function keyValuePairTypeReducer(a, _ref) {
33
+ var key = _ref.key,
34
+ value = _ref.value;
35
+ return _objectSpread$8(_objectSpread$8({}, a), {}, _defineProperty__default["default"]({}, key, value));
36
+ };
20
37
 
21
- function _classCallCheck(instance, Constructor) {
22
- if (!(instance instanceof Constructor)) {
23
- throw new TypeError("Cannot call a class as a function");
24
- }
25
- }
38
+ return keyValuePairType.reduce(keyValuePairTypeReducer, {});
39
+ };
26
40
 
27
- function _defineProperties(target, props) {
28
- for (var i = 0; i < props.length; i++) {
29
- var descriptor = props[i];
30
- descriptor.enumerable = descriptor.enumerable || false;
31
- descriptor.configurable = true;
32
- if ("value" in descriptor) descriptor.writable = true;
33
- Object.defineProperty(target, descriptor.key, descriptor);
34
- }
35
- }
41
+ var parseNowDate = function parseNowDate() {
42
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'NOW';
36
43
 
37
- function _createClass(Constructor, protoProps, staticProps) {
38
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
39
- if (staticProps) _defineProperties(Constructor, staticProps);
40
- return Constructor;
41
- }
44
+ if (value.startsWith('NOW')) {
45
+ if (value === 'NOW') return new Date();
46
+ var sign = value[3];
47
+ var number = Number(value.match(/(\d+)/)[0]);
48
+ var unit = value.match(/(\d.*)/)[0].replace(/\d/g, '');
49
+ var nowDiff = new Date();
42
50
 
43
- function _defineProperty(obj, key, value) {
44
- if (key in obj) {
45
- Object.defineProperty(obj, key, {
46
- value: value,
47
- enumerable: true,
48
- configurable: true,
49
- writable: true
50
- });
51
- } else {
52
- obj[key] = value;
53
- }
51
+ switch (unit) {
52
+ case 'HOUR':
53
+ case 'HOURS':
54
+ if (sign === '+') nowDiff.setHours(nowDiff.getHours() + number);
55
+ if (sign === '-') nowDiff.setHours(nowDiff.getHours() - number);
56
+ break;
54
57
 
55
- return obj;
56
- }
58
+ case 'DAY':
59
+ case 'DAYS':
60
+ if (sign === '+') nowDiff.setDate(nowDiff.getDate() + number);
61
+ if (sign === '-') nowDiff.setDate(nowDiff.getDate() - number);
62
+ break;
57
63
 
58
- function ownKeys(object, enumerableOnly) {
59
- var keys = Object.keys(object);
64
+ case 'MONTH':
65
+ case 'MONTHS':
66
+ if (sign === '+') nowDiff.setMonth(nowDiff.getMonth() + number);
67
+ if (sign === '-') nowDiff.setMonth(nowDiff.getMonth() - number);
68
+ break;
60
69
 
61
- if (Object.getOwnPropertySymbols) {
62
- var symbols = Object.getOwnPropertySymbols(object);
63
- if (enumerableOnly) symbols = symbols.filter(function (sym) {
64
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
- });
66
- keys.push.apply(keys, symbols);
70
+ case 'YEAR':
71
+ case 'YEARS':
72
+ if (sign === '+') nowDiff.setFullYear(nowDiff.getFullYear() + number);
73
+ if (sign === '-') nowDiff.setFullYear(nowDiff.getFullYear() - number);
74
+ break;
75
+ }
76
+
77
+ return nowDiff;
67
78
  }
68
79
 
69
- return keys;
70
- }
80
+ return new Date(value);
81
+ };
71
82
 
72
- function _objectSpread2(target) {
73
- for (var i = 1; i < arguments.length; i++) {
74
- var source = arguments[i] != null ? arguments[i] : {};
83
+ var _CONSTANT_TIMEBASES;
75
84
 
76
- if (i % 2) {
77
- ownKeys(Object(source), true).forEach(function (key) {
78
- _defineProperty(target, key, source[key]);
79
- });
80
- } else if (Object.getOwnPropertyDescriptors) {
81
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
82
- } else {
83
- ownKeys(Object(source)).forEach(function (key) {
84
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
85
- });
86
- }
85
+ var PAL = 'PAL';
86
+ var NTSC = 'NTSC';
87
+ var NTSC30 = 'NTSC30';
88
+ var CONSTANT_TIMEBASES = (_CONSTANT_TIMEBASES = {}, _defineProperty__default["default"](_CONSTANT_TIMEBASES, PAL, {
89
+ denominator: 25,
90
+ numerator: 1
91
+ }), _defineProperty__default["default"](_CONSTANT_TIMEBASES, NTSC, {
92
+ denominator: 30000,
93
+ numerator: 1001
94
+ }), _defineProperty__default["default"](_CONSTANT_TIMEBASES, NTSC30, {
95
+ denominator: 30,
96
+ numerator: 1
97
+ }), _defineProperty__default["default"](_CONSTANT_TIMEBASES, 29.97, {
98
+ denominator: 30000,
99
+ numerator: 1001
100
+ }), _defineProperty__default["default"](_CONSTANT_TIMEBASES, 59.94, {
101
+ denominator: 60000,
102
+ numerator: 1001
103
+ }), _CONSTANT_TIMEBASES);
104
+ var FRAME_SEPARATORS = {
105
+ ':': {
106
+ dropFrame: false,
107
+ field: 2
108
+ },
109
+ ';': {
110
+ dropFrame: true,
111
+ field: 2
112
+ },
113
+ '.': {
114
+ dropFrame: false,
115
+ field: 1
116
+ },
117
+ ',': {
118
+ dropFrame: true,
119
+ field: 1
87
120
  }
121
+ };
88
122
 
89
- return target;
90
- }
123
+ function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
124
+
125
+ function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$7(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
91
126
 
92
- function _objectWithoutPropertiesLoose(source, excluded) {
93
- if (source == null) return {};
94
- var target = {};
95
- var sourceKeys = Object.keys(source);
96
- var key, i;
127
+ var splitSmpte = function splitSmpte(smpteText) {
128
+ var hasDropFrameSeparator = smpteText.match(/[^0-9:\-_]/);
129
+ var hhmmssff;
130
+ var frameOptions = {};
131
+
132
+ if (hasDropFrameSeparator) {
133
+ var _hasDropFrameSeparato = _slicedToArray__default["default"](hasDropFrameSeparator, 1),
134
+ frameSeparator = _hasDropFrameSeparato[0];
135
+
136
+ var _smpteText$split = smpteText.split(frameSeparator),
137
+ _smpteText$split2 = _slicedToArray__default["default"](_smpteText$split, 2),
138
+ hhmmss = _smpteText$split2[0],
139
+ splitFrames = _smpteText$split2[1];
97
140
 
98
- for (i = 0; i < sourceKeys.length; i++) {
99
- key = sourceKeys[i];
100
- if (excluded.indexOf(key) >= 0) continue;
101
- target[key] = source[key];
141
+ hhmmssff = [].concat(_toConsumableArray__default["default"](hhmmss.split(':')), [splitFrames]);
142
+ frameOptions = FRAME_SEPARATORS[frameSeparator] || {};
143
+ } else {
144
+ hhmmssff = smpteText.split(':');
102
145
  }
103
146
 
104
- return target;
105
- }
147
+ hhmmssff = hhmmssff.map(Number);
106
148
 
107
- function _objectWithoutProperties(source, excluded) {
108
- if (source == null) return {};
149
+ if (hhmmssff.length > 4 || hhmmssff.some(function (n) {
150
+ return Number.isNaN(n);
151
+ })) {
152
+ throw new Error('Invalid SMPTE timecode');
153
+ }
109
154
 
110
- var target = _objectWithoutPropertiesLoose(source, excluded);
155
+ return [hhmmssff, frameOptions];
156
+ };
111
157
 
112
- var key, i;
158
+ var getDropFrames = function getDropFrames(roundedFrameRate) {
159
+ return roundedFrameRate === 60 ? 4 : 2;
160
+ };
113
161
 
114
- if (Object.getOwnPropertySymbols) {
115
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
162
+ var getRoundedFrameRate = function getRoundedFrameRate(timeBase) {
163
+ return Math.round(timeBase.denominator / timeBase.numerator);
164
+ };
116
165
 
117
- for (i = 0; i < sourceSymbolKeys.length; i++) {
118
- key = sourceSymbolKeys[i];
119
- if (excluded.indexOf(key) >= 0) continue;
120
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
121
- target[key] = source[key];
122
- }
166
+ var countSamples = function countSamples(hh, mm, ss, ff, _ref) {
167
+ var dropFrame = _ref.dropFrame,
168
+ roundedFrameRate = _ref.roundedFrameRate;
169
+
170
+ if (!dropFrame) {
171
+ return hh * 3600 * roundedFrameRate + mm * 60 * roundedFrameRate + ss * roundedFrameRate + ff;
123
172
  }
124
173
 
125
- return target;
126
- }
174
+ if (![30, 60].includes(roundedFrameRate)) {
175
+ throw new Error('Cannot use dropframe with non NTSC timebase');
176
+ }
127
177
 
128
- function _slicedToArray(arr, i) {
129
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
130
- }
178
+ var dropFrames = getDropFrames(roundedFrameRate);
179
+ var shouldDropMinute = mm % 10 !== 0;
180
+ var shouldDropSecond = shouldDropMinute && ss === 0;
181
+ var hourFrames = hh * (3600 * roundedFrameRate - 54 * dropFrames);
182
+ var minuteFrames = mm * 60 * roundedFrameRate - (mm - Math.ceil(mm / 10)) * dropFrames;
183
+ var secondFrames = ss * roundedFrameRate - (shouldDropMinute && ss > 1 ? dropFrames : 0);
131
184
 
132
- function _toConsumableArray(arr) {
133
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
134
- }
185
+ if (shouldDropSecond && ff < dropFrames) {
186
+ throw new Error('Invalid ff');
187
+ }
135
188
 
136
- function _arrayWithoutHoles(arr) {
137
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
138
- }
189
+ var frameFrames = shouldDropSecond ? ff - dropFrames : ff;
190
+ return hourFrames + minuteFrames + secondFrames + frameFrames;
191
+ };
139
192
 
140
- function _arrayWithHoles(arr) {
141
- if (Array.isArray(arr)) return arr;
193
+ function countDroppedFrames(frames, roundedFrameRate) {
194
+ var dropFrames = getDropFrames(roundedFrameRate);
195
+ var oneMinuteUndroppedFrames = 60 * roundedFrameRate;
196
+ var oneMinuteDroppedFrames = 60 * roundedFrameRate - dropFrames;
197
+ var tenMinuteFrames = 10 * (oneMinuteUndroppedFrames - dropFrames) + dropFrames;
198
+ var tenMinuteChunks = Math.floor(frames / tenMinuteFrames);
199
+ var minuteRemainder = Math.max(0, frames % tenMinuteFrames - oneMinuteUndroppedFrames);
200
+ var oneMinuteChunks = Math.floor(minuteRemainder / oneMinuteDroppedFrames);
201
+ var frameRemainder = minuteRemainder % oneMinuteDroppedFrames;
202
+ var frameChunks = frameRemainder > 0 ? dropFrames : 0;
203
+ return tenMinuteChunks * 9 * dropFrames + oneMinuteChunks * dropFrames + frameChunks;
142
204
  }
205
+ /**
206
+ * @class TimeBase
207
+ * @constructs formatTimeBaseText(timeBaseText: string)
208
+ */
143
209
 
144
- function _iterableToArray(iter) {
145
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
146
- }
147
210
 
148
- function _iterableToArrayLimit(arr, i) {
149
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
150
- var _arr = [];
151
- var _n = true;
152
- var _d = false;
153
- var _e = undefined;
211
+ var TimeBase = /*#__PURE__*/function () {
212
+ function TimeBase() {
213
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
214
+ _ref2$numerator = _ref2.numerator,
215
+ numerator = _ref2$numerator === void 0 ? 1 : _ref2$numerator,
216
+ _ref2$denominator = _ref2.denominator,
217
+ denominator = _ref2$denominator === void 0 ? 1 : _ref2$denominator;
154
218
 
155
- try {
156
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
157
- _arr.push(_s.value);
219
+ _classCallCheck__default["default"](this, TimeBase);
158
220
 
159
- if (i && _arr.length === i) break;
160
- }
161
- } catch (err) {
162
- _d = true;
163
- _e = err;
164
- } finally {
165
- try {
166
- if (!_n && _i["return"] != null) _i["return"]();
167
- } finally {
168
- if (_d) throw _e;
169
- }
221
+ this.numerator = Number(numerator);
222
+ this.denominator = Number(denominator);
170
223
  }
171
224
 
172
- return _arr;
173
- }
225
+ _createClass__default["default"](TimeBase, [{
226
+ key: "toJSON",
227
+ value: function toJSON() {
228
+ return {
229
+ denominator: this.denominator,
230
+ numerator: this.numerator
231
+ };
232
+ }
233
+ }, {
234
+ key: "toConstant",
235
+ value: function toConstant() {
236
+ var _this = this;
174
237
 
175
- function _unsupportedIterableToArray(o, minLen) {
176
- if (!o) return;
177
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
178
- var n = Object.prototype.toString.call(o).slice(8, -1);
179
- if (n === "Object" && o.constructor) n = o.constructor.name;
180
- if (n === "Map" || n === "Set") return Array.from(o);
181
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
182
- }
238
+ var constant;
239
+ Object.entries(CONSTANT_TIMEBASES).find(function (thisTimeBase) {
240
+ var _thisTimeBase = _slicedToArray__default["default"](thisTimeBase, 2),
241
+ thisTimeBaseText = _thisTimeBase[0],
242
+ thisTimeBaseType = _thisTimeBase[1];
183
243
 
184
- function _arrayLikeToArray(arr, len) {
185
- if (len == null || len > arr.length) len = arr.length;
244
+ var numerator = thisTimeBaseType.numerator,
245
+ denominator = thisTimeBaseType.denominator;
186
246
 
187
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
247
+ if (numerator === _this.numerator && denominator === _this.denominator) {
248
+ constant = thisTimeBaseText;
249
+ return true;
250
+ }
188
251
 
189
- return arr2;
190
- }
252
+ return false;
253
+ });
254
+ return constant;
255
+ }
256
+ }, {
257
+ key: "toText",
258
+ value: function toText() {
259
+ var useConstant = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
191
260
 
192
- function _nonIterableSpread() {
193
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
194
- }
261
+ if (useConstant) {
262
+ var _timeBaseText = this.toConstant();
195
263
 
196
- function _nonIterableRest() {
197
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
198
- }
264
+ if (_timeBaseText) return _timeBaseText;
265
+ }
199
266
 
200
- var sortTimespanList = function sortTimespanList(_ref, _ref2) {
201
- var firstStart = _ref.start;
202
- var secondStart = _ref2.start;
267
+ if (this.numerator > 1) {
268
+ var _timeBaseText2 = [this.denominator, this.numerator].join(':');
203
269
 
204
- var _firstStart$split = firstStart.split('@'),
205
- _firstStart$split2 = _slicedToArray(_firstStart$split, 1),
206
- first = _firstStart$split2[0];
270
+ return _timeBaseText2;
271
+ }
207
272
 
208
- var _secondStart$split = secondStart.split('@'),
209
- _secondStart$split2 = _slicedToArray(_secondStart$split, 1),
210
- second = _secondStart$split2[0];
273
+ var timeBaseText = String(this.denominator);
274
+ return timeBaseText;
275
+ }
276
+ }, {
277
+ key: "toRate",
278
+ value: function toRate() {
279
+ var useConstant = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
280
+ var round = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
211
281
 
212
- if (Number(first) < Number(second)) {
213
- return -1;
214
- }
282
+ if (useConstant) {
283
+ var _rate = this.toConstant();
215
284
 
216
- if (Number(first) > Number(second)) {
217
- return 1;
218
- }
285
+ if (_rate) return _rate;
286
+ }
219
287
 
220
- return 0;
221
- };
288
+ var rate = this.denominator / this.numerator;
222
289
 
223
- var findTimespan = function findTimespan() {
224
- var metadataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
225
- var start = arguments.length > 1 ? arguments[1] : undefined;
226
- var end = arguments.length > 2 ? arguments[2] : undefined;
227
- var _metadataType$timespa = metadataType.timespan,
228
- timespanList = _metadataType$timespa === void 0 ? [] : _metadataType$timespa;
229
- return timespanList.find(function (timespan) {
230
- return timespan.start === start && timespan.end === end;
231
- });
232
- };
290
+ if (Number.isInteger(rate)) {
291
+ return rate;
292
+ }
233
293
 
234
- var parseValueList = function parseValueList() {
235
- var valueList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
236
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
237
- var _options$arrayOnSingl = options.arrayOnSingle,
238
- arrayOnSingle = _options$arrayOnSingl === void 0 ? true : _options$arrayOnSingl,
239
- _options$arrayOnSingl2 = options.arrayOnSingleValue,
240
- arrayOnSingleValue = _options$arrayOnSingl2 === void 0 ? true : _options$arrayOnSingl2,
241
- joinValue = options.joinValue,
242
- includeAttributes = options.includeAttributes,
243
- includeValueAttributes = options.includeValueAttributes;
244
- if (includeAttributes || includeValueAttributes) return valueList;
245
- var valueArray = [];
246
- valueList.forEach(function (thisValue) {
247
- if (thisValue.value) valueArray.push(thisValue.value);
248
- });
249
- if (joinValue) return valueArray.join(joinValue);
250
-
251
- if ((arrayOnSingle === false || arrayOnSingleValue === false) && valueArray.length === 1) {
252
- return valueArray[0];
253
- }
254
-
255
- return valueArray;
256
- };
257
-
258
- var parseField = function parseField() {
259
- var field = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
260
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
261
- var includeAttributes = options.includeAttributes,
262
- includeFieldAttributes = options.includeFieldAttributes;
294
+ return round ? rate.toFixed(2) : rate;
295
+ }
296
+ }]);
263
297
 
264
- var _field$value = field.value,
265
- value = _field$value === void 0 ? [] : _field$value,
266
- attributes = _objectWithoutProperties(field, ["value"]);
298
+ return TimeBase;
299
+ }();
267
300
 
268
- var parsedValueList = parseValueList(value, options);
269
- if (includeAttributes || includeFieldAttributes) return _objectSpread2(_objectSpread2({}, attributes), {}, {
270
- value: parsedValueList
271
- });
272
- return parsedValueList;
301
+ var isDropFrameTimeBase = function isDropFrameTimeBase(_ref3) {
302
+ var numerator = _ref3.numerator,
303
+ denominator = _ref3.denominator;
304
+ return numerator === 1001 && (denominator === 60000 || denominator === 30000);
273
305
  };
274
306
 
275
- var parseFieldList = function parseFieldList() {
276
- var fieldList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
277
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
278
- var joinValue = options.joinValue,
279
- includeAttributes = options.includeAttributes,
280
- includeFieldAttributes = options.includeFieldAttributes,
281
- includeValueAttributes = options.includeValueAttributes;
282
- var output = {};
283
- var fieldAsList = options.fieldAsList;
284
-
285
- if (fieldAsList) {
286
- return fieldList.map(function (thisField) {
287
- return parseField(thisField, options);
288
- });
289
- }
307
+ var TimeCode = /*#__PURE__*/function () {
308
+ function TimeCode() {
309
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
310
+ _ref4$samples = _ref4.samples,
311
+ samples = _ref4$samples === void 0 ? 0 : _ref4$samples,
312
+ timeBase = _ref4.timeBase;
290
313
 
291
- fieldList.forEach(function (thisField) {
292
- var key = thisField.name;
293
- var parsedField = parseField(thisField, options);
314
+ var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
315
+ dropFrame = _ref5.dropFrame,
316
+ _ref5$field = _ref5.field,
317
+ field = _ref5$field === void 0 ? 2 : _ref5$field;
294
318
 
295
- if (output[key]) {
296
- if (includeAttributes || includeFieldAttributes) {
297
- var currentValue = output[key].value;
298
- var parsedValue = parsedField.value;
319
+ _classCallCheck__default["default"](this, TimeCode);
299
320
 
300
- if (joinValue && !includeAttributes && !includeValueAttributes) {
301
- output[key].value = [currentValue, parsedValue].join(joinValue);
302
- } else {
303
- output[key].value = parsedValue.concat(currentValue);
304
- }
321
+ if (typeof samples === 'number') {
322
+ this.samples = samples;
323
+ } else if (typeof samples === 'string') {
324
+ if (samples === '-INF') {
325
+ this.samples = -Infinity;
326
+ } else if (samples === '+INF') {
327
+ this.samples = Infinity;
305
328
  } else {
306
- var _currentValue = output[key];
307
- var _parsedValue = parsedField;
308
-
309
- if (joinValue) {
310
- output[key] = [_currentValue, _parsedValue].join(joinValue);
311
- } else {
312
- output[key] = _parsedValue.concat(_currentValue);
313
- }
329
+ this.samples = Number(samples);
314
330
  }
315
331
  } else {
316
- output[key] = parsedField;
332
+ throw new Error("samples is not number/string/-Inf/+Inf is: ".concat(samples));
317
333
  }
318
- });
319
- return output;
320
- };
321
-
322
- var parseGroup = function parseGroup() {
323
- var group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
324
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
325
- var includeAttributes = options.includeAttributes,
326
- includeGroupAttributes = options.includeGroupAttributes,
327
- flat = options.flat,
328
- flatGroup = options.flatGroup,
329
- groupAsList = options.groupAsList,
330
- fieldAsList = options.fieldAsList;
331
-
332
- var _group$field = group.field,
333
- fieldList = _group$field === void 0 ? [] : _group$field,
334
- _group$group = group.group,
335
- groupList = _group$group === void 0 ? [] : _group$group,
336
- attributes = _objectWithoutProperties(group, ["field", "group"]);
337
334
 
338
- var parsedFieldList = parseFieldList(fieldList, options);
339
- var parsedGroupList = parseGroupList(groupList, options); // eslint-disable-line no-use-before-define,max-len
335
+ this.timeBase = new TimeBase(timeBase);
336
+ this.dropFrame = dropFrame === undefined ? isDropFrameTimeBase(this.timeBase) : dropFrame;
337
+ this.field = field;
338
+ }
340
339
 
341
- var output = {};
340
+ _createClass__default["default"](TimeCode, [{
341
+ key: "add",
342
+ value: function add(val) {
343
+ var _val$timeBase = val.timeBase,
344
+ numerator = _val$timeBase.numerator,
345
+ denominator = _val$timeBase.denominator;
346
+ var conformedTimeCode = val;
342
347
 
343
- if (includeAttributes || includeGroupAttributes) {
344
- Object.assign(output, attributes);
345
- }
348
+ if (numerator !== this.timeBase.numerator || denominator !== this.timeBase.denominator) {
349
+ conformedTimeCode = val.conformTimeBase(this.timeBase);
350
+ }
346
351
 
347
- if (flat || flatGroup) {
348
- if (groupAsList) {
349
- Object.assign(output, {
350
- group: parsedGroupList
352
+ var _conformedTimeCode = conformedTimeCode,
353
+ samples = _conformedTimeCode.samples;
354
+ return new TimeCode({
355
+ samples: this.samples + samples,
356
+ timeBase: this.timeBase
351
357
  });
352
- } else {
353
- Object.assign(output, parsedGroupList);
354
358
  }
359
+ }, {
360
+ key: "subtract",
361
+ value: function subtract(val) {
362
+ var _val$timeBase2 = val.timeBase,
363
+ numerator = _val$timeBase2.numerator,
364
+ denominator = _val$timeBase2.denominator;
365
+ var conformedTimeCode = val;
355
366
 
356
- if (fieldAsList) {
357
- Object.assign(output, {
358
- field: parsedFieldList
367
+ if (numerator !== this.timeBase.numerator || denominator !== this.timeBase.denominator) {
368
+ conformedTimeCode = val.conformTimeBase(this.timeBase);
369
+ }
370
+
371
+ var _conformedTimeCode2 = conformedTimeCode,
372
+ samples = _conformedTimeCode2.samples;
373
+ return new TimeCode({
374
+ samples: this.samples - samples,
375
+ timeBase: this.timeBase
359
376
  });
360
- } else {
361
- Object.assign(output, parsedFieldList);
362
377
  }
363
- } else {
364
- Object.assign(output, {
365
- field: parsedFieldList
366
- });
367
- Object.assign(output, {
368
- group: parsedGroupList
369
- });
370
- }
371
-
372
- return output;
373
- };
374
-
375
- var parseGroupList = function parseGroupList() {
376
- var groupList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
377
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
378
- var groupAsList = options.groupAsList;
379
-
380
- if (groupAsList) {
381
- return groupList.map(function (thisGroup) {
382
- return parseGroup(thisGroup, options);
383
- });
384
- }
378
+ }, {
379
+ key: "conformTimeBase",
380
+ value: function conformTimeBase(conformTo) {
381
+ var timeBase = conformTo;
385
382
 
386
- var output = {};
387
- groupList.forEach(function (thisGroup) {
388
- var key = thisGroup.name;
389
- var parsedGroup = parseGroup(thisGroup, options);
383
+ if (conformTo instanceof TimeCode === false) {
384
+ timeBase = new TimeBase(conformTo);
385
+ }
390
386
 
391
- if (output[key]) {
392
- var _output$key = output[key],
393
- currentField = _output$key.field,
394
- currentGroup = _output$key.group;
395
- var parsedField = parsedGroup.field,
396
- parsedGroupList = parsedGroup.group;
397
- output[key].field = _objectSpread2(_objectSpread2({}, currentField), parsedField);
398
- output[key].group = _objectSpread2(_objectSpread2({}, currentGroup), parsedGroupList);
399
- } else {
400
- output[key] = parsedGroup;
387
+ var samples = Math.round(this.samples / (this.timeBase.toRate(false, false) / timeBase.toRate(false, false)));
388
+ var timeCode = {
389
+ samples: samples,
390
+ timeBase: timeBase
391
+ };
392
+ return new TimeCode(timeCode);
401
393
  }
402
- });
403
- return output;
404
- };
405
-
406
- var parseTimespan = function parseTimespan() {
407
- var timespan = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
408
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
409
- var includeAttributes = options.includeAttributes,
410
- includeTimespanAttributes = options.includeTimespanAttributes,
411
- flat = options.flat,
412
- flatTimespan = options.flatTimespan,
413
- groupAsList = options.groupAsList,
414
- fieldAsList = options.fieldAsList;
415
-
416
- var _timespan$field = timespan.field,
417
- fieldList = _timespan$field === void 0 ? [] : _timespan$field,
418
- _timespan$group = timespan.group,
419
- groupList = _timespan$group === void 0 ? [] : _timespan$group,
420
- attributes = _objectWithoutProperties(timespan, ["field", "group"]);
421
-
422
- var field = parseFieldList(fieldList, options);
423
- var group = parseGroupList(groupList, options);
424
- var output = {};
394
+ }, {
395
+ key: "toJSON",
396
+ value: function toJSON() {
397
+ return {
398
+ samples: this.samples,
399
+ timeBase: this.timeBase
400
+ };
401
+ }
402
+ }, {
403
+ key: "toText",
404
+ value: function toText() {
405
+ var timeCodeText = String(this.samples);
406
+ var timeBaseText = this.timeBase.toText();
425
407
 
426
- if (includeAttributes || includeTimespanAttributes) {
427
- Object.assign(output, attributes);
428
- }
408
+ if (timeBaseText !== '1') {
409
+ timeCodeText = [this.samples, timeBaseText].join('@');
410
+ }
429
411
 
430
- if (flat || flatTimespan) {
431
- if (groupAsList) {
432
- Object.assign(output, {
433
- group: group
434
- });
435
- } else {
436
- Object.assign(output, group);
412
+ return timeCodeText;
437
413
  }
438
-
439
- if (fieldAsList) {
440
- Object.assign(output, {
441
- field: field
442
- });
443
- } else {
444
- Object.assign(output, field);
414
+ }, {
415
+ key: "toSeconds",
416
+ value: function toSeconds() {
417
+ var _this$timeBase = this.timeBase,
418
+ numerator = _this$timeBase.numerator,
419
+ denominator = _this$timeBase.denominator;
420
+ return this.samples * (numerator / denominator);
445
421
  }
446
- } else {
447
- Object.assign(output, {
448
- field: field
449
- });
450
- Object.assign(output, {
451
- group: group
452
- });
453
- }
422
+ }, {
423
+ key: "toTime",
424
+ value: function toTime() {
425
+ var roundedFrameRate = getRoundedFrameRate(this.timeBase);
426
+ var totalSamples = this.samples + (this.dropFrame ? countDroppedFrames(this.samples + 1, roundedFrameRate) : 0);
427
+ var hours = Math.floor(totalSamples / (3600 * roundedFrameRate));
428
+ var minutes = Math.floor(totalSamples / (60 * roundedFrameRate)) % 60;
429
+ var seconds = Math.floor(totalSamples / roundedFrameRate) % 60;
430
+ var frames = totalSamples % roundedFrameRate;
431
+ var partialSeconds = frames / roundedFrameRate;
432
+ return {
433
+ hours: hours,
434
+ minutes: minutes,
435
+ seconds: seconds,
436
+ frames: frames,
437
+ partialSeconds: partialSeconds
438
+ };
439
+ }
440
+ }, {
441
+ key: "toDuration",
442
+ value: function toDuration() {
443
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
444
+ format = _ref6.format;
454
445
 
455
- return output;
456
- };
446
+ var _this$toTime = this.toTime(),
447
+ hours = _this$toTime.hours,
448
+ minutes = _this$toTime.minutes,
449
+ seconds = _this$toTime.seconds;
457
450
 
458
- var parseTimespanList = function parseTimespanList() {
459
- var timespanList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
460
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
461
- var joinTimespan = options.joinTimespan,
462
- flat = options.flat;
463
- var timespanAsList = options.timespanAsList;
451
+ if (typeof format === 'string') {
452
+ if (format.toLowerCase() === 'hhmmss') {
453
+ return [hours.toFixed().padStart(2, '0'), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
454
+ }
455
+ }
464
456
 
465
- if (timespanAsList) {
466
- return timespanList.map(function (thisTimespan) {
467
- return parseTimespan(thisTimespan, options);
468
- });
469
- }
457
+ if (hours) {
458
+ return [hours.toFixed(), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
459
+ }
470
460
 
471
- var output = {};
472
- timespanList.forEach(function (thisTimespan) {
473
- var start = thisTimespan.start,
474
- end = thisTimespan.end;
475
- var key = [start, end].join(joinTimespan || '_');
476
- var parsedTimespan = parseTimespan(thisTimespan, options);
461
+ if (minutes >= 10) {
462
+ return [minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
463
+ }
477
464
 
478
- if (flat) {
479
- output = _objectSpread2(_objectSpread2({}, output), parsedTimespan);
480
- } else if (output[key]) {
481
- var _output$key2 = output[key],
482
- currentField = _output$key2.field,
483
- currentGroup = _output$key2.group;
484
- var parsedField = parsedTimespan.field,
485
- parsedGroup = parsedTimespan.group;
486
- output[key].field = _objectSpread2(_objectSpread2({}, currentField), parsedField);
487
- output[key].group = _objectSpread2(_objectSpread2({}, currentGroup), parsedGroup);
488
- } else {
489
- output[key] = parsedTimespan;
465
+ return [minutes.toFixed(), seconds.toFixed().padStart(2, '0')].join(':');
490
466
  }
491
- });
492
- return output;
493
- };
494
- /**
495
- * Parses MetadataType into key/value object.
496
- * The attributes can be targeted for each sub-type.
497
- * @param {Object} metadataType - The response from the API.
498
- * @param {Object} options - Options which change how the metadataType is parsed.
499
- * @param {Object} options.joinValue - String to join the values, eg ','.
500
- * @param {Object} options.includeAttributes - include attributes on all objects.
501
- * @param {Object} options.includeMetadataAttributes - include attributes on root.
502
- * @param {Object} options.includeTimespanAttributes - include attributes on timespans.
503
- * @param {Object} options.includeGroupAttributes - include attributes on groups.
504
- * @param {Object} options.includeFieldAttributes - include attributes on fields.
505
- * @param {Object} options.includeValueAttributes - include attributes on values.
506
- * @param {Object} options.flat - Flatten to key/value (Note: keys may be overwritten).
507
- * @param {Object} options.flatTimespan - Flatten timespan.
508
- * @param {Object} options.flatGroup - Flatten group.
509
- * @param {Object} options.sortTimespan - Sort timespan by start time.
510
- * @param {Object} options.timespanAsList -Return timespans as list.
511
- * @param {Object} options.groupAsList -Return groups as list.
512
- * @param {Object} options.fieldAsList -Return fields as list.
513
- */
467
+ }, {
468
+ key: "toSmpte",
469
+ value: function toSmpte() {
470
+ var _this2 = this;
514
471
 
472
+ if (this.samples === -Infinity) return '00:00:00:00';
515
473
 
516
- var parseMetadataType = function parseMetadataType() {
517
- var metadataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
518
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
519
- var includeAttributes = options.includeAttributes,
520
- includeMetadataAttributes = options.includeMetadataAttributes,
521
- sortTimespan = options.sortTimespan;
474
+ var _this$toTime2 = this.toTime(),
475
+ hours = _this$toTime2.hours,
476
+ minutes = _this$toTime2.minutes,
477
+ seconds = _this$toTime2.seconds,
478
+ frames = _this$toTime2.frames;
522
479
 
523
- var _metadataType$timespa2 = metadataType.timespan,
524
- timespanList = _metadataType$timespa2 === void 0 ? [] : _metadataType$timespa2,
525
- attributes = _objectWithoutProperties(metadataType, ["timespan"]);
480
+ var hhmmss = [hours.toFixed().padStart(2, '0'), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
526
481
 
527
- if (sortTimespan) timespanList.sort(sortTimespanList);
528
- var timespan = parseTimespanList(timespanList, options);
482
+ var _Object$entries$find = Object.entries(FRAME_SEPARATORS).find(function (thisSeparator) {
483
+ var _thisSeparator = _slicedToArray__default["default"](thisSeparator, 2),
484
+ _thisSeparator$ = _thisSeparator[1],
485
+ dropFrame = _thisSeparator$.dropFrame,
486
+ field = _thisSeparator$.field;
529
487
 
530
- if (includeAttributes || includeMetadataAttributes) {
531
- Object.assign(timespan, attributes);
532
- }
488
+ return dropFrame === _this2.dropFrame && field === _this2.field;
489
+ }),
490
+ _Object$entries$find2 = _slicedToArray__default["default"](_Object$entries$find, 1),
491
+ _Object$entries$find3 = _Object$entries$find2[0],
492
+ frameSeparator = _Object$entries$find3 === void 0 ? ':' : _Object$entries$find3;
533
493
 
534
- return timespan;
535
- };
494
+ return [hhmmss, frames.toFixed().padStart(2, '0')].join(frameSeparator);
495
+ }
496
+ }, {
497
+ key: "toFraction",
498
+ value: function toFraction() {
499
+ return "".concat(this.samples, "@").concat(this.timeBase.denominator, ":").concat(this.timeBase.numerator);
500
+ }
501
+ }]);
536
502
 
537
- function createCommonjsModule(fn, module) {
538
- return module = { exports: {} }, fn(module, module.exports), module.exports;
539
- }
503
+ return TimeCode;
504
+ }();
540
505
 
541
- var filesize = createCommonjsModule(function (module, exports) {
542
- /**
543
- * filesize
544
- *
545
- * @copyright 2020 Jason Mulligan <jason.mulligan@avoidwork.com>
546
- * @license BSD-3-Clause
547
- * @version 6.1.0
548
- */
549
-
550
- (function (global) {
551
- var b = /^(b|B)$/,
552
- symbol = {
553
- iec: {
554
- bits: ["b", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib"],
555
- bytes: ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
556
- },
557
- jedec: {
558
- bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
559
- bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
560
- }
561
- },
562
- fullform = {
563
- iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"],
564
- jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"]
565
- };
566
- /**
567
- * filesize
568
- *
569
- * @method filesize
570
- * @param {Mixed} arg String, Int or Float to transform
571
- * @param {Object} descriptor [Optional] Flags
572
- * @return {String} Readable file size String
573
- */
574
-
575
- function filesize(arg) {
576
- var descriptor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
577
- var result = [],
578
- val = 0,
579
- e = void 0,
580
- base = void 0,
581
- bits = void 0,
582
- ceil = void 0,
583
- full = void 0,
584
- fullforms = void 0,
585
- locale = void 0,
586
- localeOptions = void 0,
587
- neg = void 0,
588
- num = void 0,
589
- output = void 0,
590
- round = void 0,
591
- unix = void 0,
592
- separator = void 0,
593
- spacer = void 0,
594
- standard = void 0,
595
- symbols = void 0;
596
-
597
- if (isNaN(arg)) {
598
- throw new TypeError("Invalid number");
599
- }
506
+ var formatTimeBaseType = function formatTimeBaseType(timeBase) {
507
+ return new TimeBase(timeBase);
508
+ };
600
509
 
601
- bits = descriptor.bits === true;
602
- unix = descriptor.unix === true;
603
- base = descriptor.base || 2;
604
- round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
605
- locale = descriptor.locale !== void 0 ? descriptor.locale : "";
606
- localeOptions = descriptor.localeOptions || {};
607
- separator = descriptor.separator !== void 0 ? descriptor.separator : "";
608
- spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
609
- symbols = descriptor.symbols || {};
610
- standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
611
- output = descriptor.output || "string";
612
- full = descriptor.fullform === true;
613
- fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
614
- e = descriptor.exponent !== void 0 ? descriptor.exponent : -1;
615
- num = Number(arg);
616
- neg = num < 0;
617
- ceil = base > 2 ? 1000 : 1024; // Flipping a negative number to determine the size
618
-
619
- if (neg) {
620
- num = -num;
621
- } // Determining the exponent
622
-
623
-
624
- if (e === -1 || isNaN(e)) {
625
- e = Math.floor(Math.log(num) / Math.log(ceil));
626
-
627
- if (e < 0) {
628
- e = 0;
629
- }
630
- } // Exceeding supported length, time to reduce & multiply
510
+ var formatTimeBaseText = function formatTimeBaseText(timeBaseText) {
511
+ if (timeBaseText === undefined) {
512
+ return formatTimeBaseType();
513
+ }
631
514
 
515
+ if (typeof timeBaseText === 'number') {
516
+ return formatTimeBaseType({
517
+ denominator: timeBaseText
518
+ });
519
+ }
632
520
 
633
- if (e > 8) {
634
- e = 8;
635
- }
521
+ if (timeBaseText.includes(':')) {
522
+ var _timeBaseText$split = timeBaseText.split(':'),
523
+ _timeBaseText$split2 = _slicedToArray__default["default"](_timeBaseText$split, 2),
524
+ _denominator = _timeBaseText$split2[0],
525
+ numerator = _timeBaseText$split2[1];
636
526
 
637
- if (output === "exponent") {
638
- return e;
639
- } // Zero is now a special case because bytes divide by 1
527
+ return formatTimeBaseType({
528
+ denominator: _denominator,
529
+ numerator: numerator
530
+ });
531
+ }
640
532
 
533
+ if (Object.keys(CONSTANT_TIMEBASES).includes(timeBaseText)) {
534
+ return formatTimeBaseType(CONSTANT_TIMEBASES[timeBaseText]);
535
+ }
641
536
 
642
- if (num === 0) {
643
- result[0] = 0;
644
- result[1] = unix ? "" : symbol[standard][bits ? "bits" : "bytes"][e];
645
- } else {
646
- val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
537
+ var denominator = Number(timeBaseText);
647
538
 
648
- if (bits) {
649
- val = val * 8;
539
+ if (Number.isNaN(denominator)) {
540
+ throw new Error("timeBaseText must be a number or ".concat(Object.keys(CONSTANT_TIMEBASES).join(','), " - is ").concat(timeBaseText));
541
+ }
650
542
 
651
- if (val >= ceil && e < 8) {
652
- val = val / ceil;
653
- e++;
654
- }
655
- }
543
+ return formatTimeBaseType({
544
+ denominator: denominator
545
+ });
546
+ };
656
547
 
657
- result[0] = Number(val.toFixed(e > 0 ? round : 0));
548
+ var formatTimeBase = function formatTimeBase(timeBase) {
549
+ if (_typeof__default["default"](timeBase) === 'object') {
550
+ return formatTimeBaseType(timeBase);
551
+ }
658
552
 
659
- if (result[0] === ceil && e < 8 && descriptor.exponent === void 0) {
660
- result[0] = 1;
661
- e++;
662
- }
553
+ return formatTimeBaseText(timeBase);
554
+ };
663
555
 
664
- result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
556
+ var formatTimeCodeType = function formatTimeCodeType(timeCode, options) {
557
+ return new TimeCode(timeCode, options);
558
+ };
665
559
 
666
- if (unix) {
667
- result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1];
560
+ var formatTimeCodeText = function formatTimeCodeText(timeCodeText, options) {
561
+ if (timeCodeText === undefined) {
562
+ var _timeCode = {
563
+ samples: 0
564
+ };
565
+ return formatTimeCodeType(_timeCode, options);
566
+ }
668
567
 
669
- if (b.test(result[1])) {
670
- result[0] = Math.floor(result[0]);
671
- result[1] = "";
672
- }
673
- }
674
- } // Decorating a 'diff'
568
+ if (typeof timeCodeText === 'number') {
569
+ var _timeCode2 = {
570
+ samples: timeCodeText
571
+ };
572
+ return formatTimeCodeType(_timeCode2, options);
573
+ }
675
574
 
575
+ if (timeCodeText.includes('@')) {
576
+ var _timeCodeText$split = timeCodeText.split('@'),
577
+ _timeCodeText$split2 = _slicedToArray__default["default"](_timeCodeText$split, 2),
578
+ samplesString = _timeCodeText$split2[0],
579
+ timeBaseText = _timeCodeText$split2[1];
676
580
 
677
- if (neg) {
678
- result[0] = -result[0];
679
- } // Applying custom symbol
581
+ var _samples = Number(samplesString);
680
582
 
583
+ var timeBase = formatTimeBaseText(timeBaseText);
584
+ var _timeCode3 = {
585
+ samples: _samples,
586
+ timeBase: timeBase
587
+ };
588
+ return formatTimeCodeType(_timeCode3, options);
589
+ }
681
590
 
682
- result[1] = symbols[result[1]] || result[1];
591
+ if (timeCodeText === '-INF') {
592
+ var _samples2 = -Infinity;
683
593
 
684
- if (locale === true) {
685
- result[0] = result[0].toLocaleString();
686
- } else if (locale.length > 0) {
687
- result[0] = result[0].toLocaleString(locale, localeOptions);
688
- } else if (separator.length > 0) {
689
- result[0] = result[0].toString().replace(".", separator);
690
- } // Returning Array, Object, or String (default)
594
+ var _timeCode4 = {
595
+ samples: _samples2
596
+ };
597
+ return formatTimeCodeType(_timeCode4, options);
598
+ }
691
599
 
600
+ if (timeCodeText === '+INF') {
601
+ var _samples3 = Infinity;
602
+ var _timeCode5 = {
603
+ samples: _samples3
604
+ };
605
+ return formatTimeCodeType(_timeCode5, options);
606
+ }
692
607
 
693
- if (output === "array") {
694
- return result;
695
- }
608
+ var samples = Number(timeCodeText);
696
609
 
697
- if (full) {
698
- result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
699
- }
610
+ if (Number.isNaN(samples)) {
611
+ throw new Error("timeBaseText must be a number or sample@timeBase - is ".concat(timeCodeText));
612
+ }
700
613
 
701
- if (output === "object") {
702
- return {
703
- value: result[0],
704
- symbol: result[1],
705
- exponent: e
706
- };
707
- }
614
+ var timeCode = {
615
+ samples: samples
616
+ };
617
+ return formatTimeCodeType(timeCode, options);
618
+ };
708
619
 
709
- return result.join(spacer);
710
- } // Partial application for functional programming
620
+ var formatSeconds = function formatSeconds(seconds, timeBase, options) {
621
+ if (Number.isNaN(Number(seconds))) {
622
+ throw new Error("seconds must be digits, is ".concat(seconds));
623
+ }
711
624
 
625
+ var _ref7 = timeBase || {},
626
+ _ref7$denominator = _ref7.denominator,
627
+ denominator = _ref7$denominator === void 0 ? 1 : _ref7$denominator,
628
+ _ref7$numerator = _ref7.numerator,
629
+ numerator = _ref7$numerator === void 0 ? 1 : _ref7$numerator;
712
630
 
713
- filesize.partial = function (opt) {
714
- return function (arg) {
715
- return filesize(arg, opt);
716
- };
717
- }; // CommonJS, AMD, script tag
631
+ var samples = seconds * (denominator / numerator);
632
+ var timeCode = {
633
+ samples: samples,
634
+ timeBase: timeBase || {}
635
+ };
636
+ return new TimeCode(timeCode, options);
637
+ };
718
638
 
639
+ var formatSecondsPrecise = function formatSecondsPrecise(seconds, timeBase, options) {
640
+ if (Number.isNaN(Number(seconds))) {
641
+ throw new Error("seconds must be digits, is ".concat(seconds));
642
+ }
719
643
 
720
- {
721
- module.exports = filesize;
722
- }
723
- })();
724
- });
644
+ var _ref8 = timeBase || {},
645
+ _ref8$numerator = _ref8.numerator,
646
+ numerator = _ref8$numerator === void 0 ? 1 : _ref8$numerator;
725
647
 
726
- var _CONSTANT_TIMEBASES;
648
+ var _ref9 = timeBase || {},
649
+ _ref9$denominator = _ref9.denominator,
650
+ denominator = _ref9$denominator === void 0 ? 1 : _ref9$denominator;
727
651
 
728
- var PAL = 'PAL';
729
- var NTSC = 'NTSC';
730
- var NTSC30 = 'NTSC30';
731
- var CONSTANT_TIMEBASES = (_CONSTANT_TIMEBASES = {}, _defineProperty(_CONSTANT_TIMEBASES, PAL, {
732
- denominator: 25,
733
- numerator: 1
734
- }), _defineProperty(_CONSTANT_TIMEBASES, NTSC, {
735
- denominator: 30000,
736
- numerator: 1001
737
- }), _defineProperty(_CONSTANT_TIMEBASES, NTSC30, {
738
- denominator: 30,
739
- numerator: 1
740
- }), _defineProperty(_CONSTANT_TIMEBASES, 29.97, {
741
- denominator: 30000,
742
- numerator: 1001
743
- }), _defineProperty(_CONSTANT_TIMEBASES, 59.94, {
744
- denominator: 60000,
745
- numerator: 1001
746
- }), _CONSTANT_TIMEBASES);
747
- var FRAME_SEPARATORS = {
748
- ':': {
749
- dropFrame: false,
750
- field: 2
751
- },
752
- ';': {
753
- dropFrame: true,
754
- field: 2
755
- },
756
- '.': {
757
- dropFrame: false,
758
- field: 1
759
- },
760
- ',': {
761
- dropFrame: true,
762
- field: 1
652
+ if (!Number.isInteger(seconds)) {
653
+ var decimalPlaces = String(seconds).split('.')[1].length;
654
+ denominator *= Math.pow(10, decimalPlaces);
763
655
  }
656
+
657
+ var samples = (seconds * (denominator / numerator)).toFixed();
658
+ var timeCode = {
659
+ samples: samples,
660
+ timeBase: {
661
+ denominator: denominator,
662
+ numerator: numerator
663
+ }
664
+ };
665
+ return new TimeCode(timeCode, options);
764
666
  };
765
667
 
766
- var splitSmpte = function splitSmpte(smpteText) {
767
- var hasDropFrameSeparator = smpteText.match(/[^0-9:\-_]/);
768
- var hhmmssff;
769
- var frameOptions = {};
668
+ var formatSmpte = function formatSmpte(smpteText, timeBaseText) {
669
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
770
670
 
771
- if (hasDropFrameSeparator) {
772
- var _hasDropFrameSeparato = _slicedToArray(hasDropFrameSeparator, 1),
773
- frameSeparator = _hasDropFrameSeparato[0];
671
+ if (smpteText === undefined) {
672
+ var _timeBase = formatTimeBase(timeBaseText);
774
673
 
775
- var _smpteText$split = smpteText.split(frameSeparator),
776
- _smpteText$split2 = _slicedToArray(_smpteText$split, 2),
777
- hhmmss = _smpteText$split2[0],
778
- splitFrames = _smpteText$split2[1];
674
+ var _timeCode6 = {
675
+ samples: 0,
676
+ timeBase: _timeBase
677
+ };
678
+ return formatTimeCodeType(_timeCode6);
679
+ }
779
680
 
780
- hhmmssff = [].concat(_toConsumableArray(hhmmss.split(':')), [splitFrames]);
781
- frameOptions = FRAME_SEPARATORS[frameSeparator] || {};
782
- } else {
783
- hhmmssff = smpteText.split(':');
681
+ if (typeof smpteText !== 'string') {
682
+ throw new Error("smpteText must be a string, is ".concat(smpteText));
784
683
  }
785
684
 
786
- hhmmssff = hhmmssff.map(Number);
685
+ var _splitSmpte = splitSmpte(smpteText),
686
+ _splitSmpte2 = _slicedToArray__default["default"](_splitSmpte, 2),
687
+ _splitSmpte2$ = _slicedToArray__default["default"](_splitSmpte2[0], 4),
688
+ hh = _splitSmpte2$[0],
689
+ mm = _splitSmpte2$[1],
690
+ ss = _splitSmpte2$[2],
691
+ _splitSmpte2$$ = _splitSmpte2$[3],
692
+ ff = _splitSmpte2$$ === void 0 ? 0 : _splitSmpte2$$,
693
+ frameOptions = _splitSmpte2[1];
787
694
 
788
- if (hhmmssff.length > 4 || hhmmssff.some(function (n) {
789
- return Number.isNaN(n);
790
- })) {
791
- throw new Error('Invalid SMPTE timecode');
695
+ var _frameOptions$dropFra = frameOptions.dropFrame,
696
+ dropFrame = _frameOptions$dropFra === void 0 ? false : _frameOptions$dropFra;
697
+ var timeBase = formatTimeBase(timeBaseText);
698
+ var roundedFrameRate = getRoundedFrameRate(timeBase);
699
+
700
+ if (mm >= 60 || mm < 0 || ss >= 60 || ss < 0 || ff >= roundedFrameRate || ff < 0) {
701
+ throw new Error('Invalid mm, ss or ff');
792
702
  }
793
703
 
794
- return [hhmmssff, frameOptions];
704
+ var samples = countSamples(hh, mm, ss, ff, {
705
+ dropFrame: dropFrame,
706
+ roundedFrameRate: roundedFrameRate
707
+ });
708
+ var timeCode = {
709
+ samples: samples,
710
+ timeBase: timeBase
711
+ };
712
+ return formatTimeCodeType(timeCode, _objectSpread$7(_objectSpread$7({}, frameOptions), options));
795
713
  };
796
714
 
797
- var getDropFrames = function getDropFrames(roundedFrameRate) {
798
- return roundedFrameRate === 60 ? 4 : 2;
715
+ var _excluded$4 = ["property"];
716
+
717
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
718
+
719
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
720
+ var sampleRateSymbols = {
721
+ kB: 'kHz',
722
+ B: 'Hz',
723
+ mB: 'mHz'
724
+ };
725
+ var bitRateSymbols = {
726
+ kB: 'kbps',
727
+ B: 'bps',
728
+ MB: 'mbps'
799
729
  };
800
730
 
801
- var getRoundedFrameRate = function getRoundedFrameRate(timeBase) {
802
- return Math.round(timeBase.denominator / timeBase.numerator);
731
+ var gcd = function gcd(a, b) {
732
+ return b ? gcd(b, a % b) : a;
803
733
  };
804
734
 
805
- var countSamples = function countSamples(hh, mm, ss, ff, _ref) {
806
- var dropFrame = _ref.dropFrame,
807
- roundedFrameRate = _ref.roundedFrameRate;
735
+ var parseAspectRatio = function parseAspectRatio(_ref) {
736
+ var width = _ref.width,
737
+ height = _ref.height;
738
+ var denominator = gcd(width, height);
739
+ var widthRatio = width / denominator;
740
+ var heightRatio = height / denominator;
808
741
 
809
- if (!dropFrame) {
810
- return hh * 3600 * roundedFrameRate + mm * 60 * roundedFrameRate + ss * roundedFrameRate + ff;
742
+ if (widthRatio > 21) {
743
+ heightRatio = 1;
744
+ widthRatio = (width / height).toFixed(2);
811
745
  }
812
746
 
813
- if (![30, 60].includes(roundedFrameRate)) {
814
- throw new Error('Cannot use dropframe with non NTSC timebase');
815
- }
747
+ return [widthRatio, heightRatio].join(':');
748
+ };
816
749
 
817
- var dropFrames = getDropFrames(roundedFrameRate);
818
- var shouldDropMinute = mm % 10 !== 0;
819
- var shouldDropSecond = shouldDropMinute && ss === 0;
820
- var hourFrames = hh * (3600 * roundedFrameRate - 54 * dropFrames);
821
- var minuteFrames = mm * 60 * roundedFrameRate - (mm - Math.ceil(mm / 10)) * dropFrames;
822
- var secondFrames = ss * roundedFrameRate - (shouldDropMinute && ss > 1 ? dropFrames : 0);
750
+ var parseBaseMediaInfoType = function parseBaseMediaInfoType() {
751
+ var baseMediaInfoType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
823
752
 
824
- if (shouldDropSecond && ff < dropFrames) {
825
- throw new Error('Invalid ff');
826
- }
753
+ var keyValuePairType = baseMediaInfoType.property,
754
+ props = _objectWithoutProperties__default["default"](baseMediaInfoType, _excluded$4);
827
755
 
828
- var frameFrames = shouldDropSecond ? ff - dropFrames : ff;
829
- return hourFrames + minuteFrames + secondFrames + frameFrames;
756
+ var parsedKeyValuePairType = parseKeyValuePairType(keyValuePairType);
757
+ return _objectSpread$6(_objectSpread$6({}, parsedKeyValuePairType), props);
830
758
  };
831
759
 
832
- function countDroppedFrames(frames, roundedFrameRate) {
833
- var dropFrames = getDropFrames(roundedFrameRate);
834
- var oneMinuteUndroppedFrames = 60 * roundedFrameRate;
835
- var oneMinuteDroppedFrames = 60 * roundedFrameRate - dropFrames;
836
- var tenMinuteFrames = 10 * (oneMinuteUndroppedFrames - dropFrames) + dropFrames;
837
- var tenMinuteChunks = Math.floor(frames / tenMinuteFrames);
838
- var minuteRemainder = Math.max(0, frames % tenMinuteFrames - oneMinuteUndroppedFrames);
839
- var oneMinuteChunks = Math.floor(minuteRemainder / oneMinuteDroppedFrames);
840
- var frameRemainder = minuteRemainder % oneMinuteDroppedFrames;
841
- var frameChunks = frameRemainder > 0 ? dropFrames : 0;
842
- return tenMinuteChunks * 9 * dropFrames + oneMinuteChunks * dropFrames + frameChunks;
843
- }
844
-
845
- var TimeBase = /*#__PURE__*/function () {
846
- function TimeBase() {
847
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
848
- _ref2$numerator = _ref2.numerator,
849
- numerator = _ref2$numerator === void 0 ? 1 : _ref2$numerator,
850
- _ref2$denominator = _ref2.denominator,
851
- denominator = _ref2$denominator === void 0 ? 1 : _ref2$denominator;
760
+ var parseFileType = function parseFileType(fileType) {
761
+ var _fileType$uri = fileType.uri,
762
+ uriList = _fileType$uri === void 0 ? [] : _fileType$uri,
763
+ fileSizeBytes = fileType.size,
764
+ hash = fileType.hash,
765
+ path = fileType.path,
766
+ fileId = fileType.id;
852
767
 
853
- _classCallCheck(this, TimeBase);
768
+ var _uriList = _slicedToArray__default["default"](uriList, 1),
769
+ uri = _uriList[0];
854
770
 
855
- this.numerator = Number(numerator);
856
- this.denominator = Number(denominator);
857
- }
771
+ var fileSize = fileSizeBytes !== undefined ? parseFileSize__default["default"](fileSizeBytes) : '';
772
+ var fileName = path ? path.split('/').pop() : undefined;
773
+ return {
774
+ uri: uri,
775
+ hash: hash,
776
+ fileSize: fileSize,
777
+ fileSizeBytes: fileSizeBytes,
778
+ path: path,
779
+ fileName: fileName,
780
+ fileId: fileId
781
+ };
782
+ };
858
783
 
859
- _createClass(TimeBase, [{
860
- key: "toJSON",
861
- value: function toJSON() {
862
- return {
863
- denominator: this.denominator,
864
- numerator: this.numerator
865
- };
866
- }
867
- }, {
868
- key: "toConstant",
869
- value: function toConstant() {
870
- var _this = this;
784
+ var parseContainerComponent = function parseContainerComponent(containerComponent) {
785
+ var _containerComponent$m = containerComponent.mediaInfo,
786
+ mediaInfo = _containerComponent$m === void 0 ? {} : _containerComponent$m,
787
+ _containerComponent$m2 = containerComponent.metadata,
788
+ metadata = _containerComponent$m2 === void 0 ? [] : _containerComponent$m2,
789
+ fileList = containerComponent.file,
790
+ durationTimeCode = containerComponent.duration,
791
+ startTimestamp = containerComponent.startTimestamp,
792
+ startTimecode = containerComponent.startTimecode,
793
+ timeCodeTimeBase = containerComponent.timeCodeTimeBase;
794
+ var containerMetadata = parseKeyValuePairType(metadata);
795
+ var containerMediaInfo = parseBaseMediaInfoType(mediaInfo);
796
+ var containerFormat = containerMediaInfo.Format;
797
+ var videoFormat = containerMediaInfo.Video_Format_List,
798
+ audioFormat = containerMediaInfo.Audio_Format_List,
799
+ textFormat = containerMediaInfo.Text_Format_List;
871
800
 
872
- var constant;
873
- Object.entries(CONSTANT_TIMEBASES).find(function (thisTimeBase) {
874
- var _thisTimeBase = _slicedToArray(thisTimeBase, 2),
875
- thisTimeBaseText = _thisTimeBase[0],
876
- thisTimeBaseType = _thisTimeBase[1];
801
+ if (containerFormat === undefined) {
802
+ var format = containerComponent.format;
803
+ containerFormat = format;
877
804
 
878
- var numerator = thisTimeBaseType.numerator,
879
- denominator = thisTimeBaseType.denominator;
805
+ if (format && format.includes(',')) {
806
+ var formatList = format.split(',');
880
807
 
881
- if (numerator === _this.numerator && denominator === _this.denominator) {
882
- constant = thisTimeBaseText;
883
- return true;
884
- }
808
+ var _formatList = _slicedToArray__default["default"](formatList, 1);
885
809
 
886
- return false;
887
- });
888
- return constant;
810
+ containerFormat = _formatList[0];
889
811
  }
890
- }, {
891
- key: "toText",
892
- value: function toText() {
893
- var useConstant = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
812
+ }
894
813
 
895
- if (useConstant) {
896
- var _timeBaseText = this.toConstant();
814
+ var parsedContainerComponent = {
815
+ containerFormat: containerFormat,
816
+ videoFormat: videoFormat,
817
+ audioFormat: audioFormat,
818
+ textFormat: textFormat,
819
+ containerMetadata: containerMetadata,
820
+ containerMediaInfo: containerMediaInfo
821
+ };
897
822
 
898
- if (_timeBaseText) return _timeBaseText;
899
- }
823
+ if (containerMetadata.componentOriginalFilename) {
824
+ parsedContainerComponent.originalFilename = containerMetadata.componentOriginalFilename;
825
+ }
900
826
 
901
- if (this.numerator > 1) {
902
- var _timeBaseText2 = [this.denominator, this.numerator].join(':');
827
+ if (durationTimeCode !== undefined && durationTimeCode.samples !== 0) {
828
+ parsedContainerComponent.durationTimeCode = formatTimeCodeType(durationTimeCode);
829
+ parsedContainerComponent.duration = parsedContainerComponent.durationTimeCode.toDuration();
830
+ }
903
831
 
904
- return _timeBaseText2;
905
- }
832
+ if (startTimestamp) {
833
+ parsedContainerComponent.startTimestamp = formatTimeCodeType(startTimestamp);
834
+ }
906
835
 
907
- var timeBaseText = String(this.denominator);
908
- return timeBaseText;
909
- }
910
- }, {
911
- key: "toRate",
912
- value: function toRate() {
913
- var useConstant = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
914
- var round = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
836
+ if (startTimecode !== undefined && timeCodeTimeBase) {
837
+ parsedContainerComponent.startTimecode = formatTimeCodeType({
838
+ samples: startTimecode,
839
+ timeBase: timeCodeTimeBase
840
+ });
841
+ }
915
842
 
916
- if (useConstant) {
917
- var _rate = this.toConstant();
843
+ if (fileList) {
844
+ var _fileList = _slicedToArray__default["default"](fileList, 1),
845
+ fileType = _fileList[0];
918
846
 
919
- if (_rate) return _rate;
920
- }
847
+ var parsedFileType = parseFileType(fileType);
848
+ parsedContainerComponent = _objectSpread$6(_objectSpread$6({}, parsedContainerComponent), parsedFileType);
849
+ }
921
850
 
922
- var rate = this.denominator / this.numerator;
851
+ return parsedContainerComponent;
852
+ };
923
853
 
924
- if (Number.isInteger(rate)) {
925
- return rate;
926
- }
854
+ var parseVideoComponent = function parseVideoComponent(videoComponent) {
855
+ var videoCodec = videoComponent.codec,
856
+ bitrate = videoComponent.bitrate,
857
+ fieldOrder = videoComponent.fieldOrder,
858
+ _videoComponent$resol = videoComponent.resolution,
859
+ resolution = _videoComponent$resol === void 0 ? {} : _videoComponent$resol,
860
+ _videoComponent$media = videoComponent.mediaInfo,
861
+ mediaInfo = _videoComponent$media === void 0 ? {} : _videoComponent$media,
862
+ _videoComponent$metad = videoComponent.metadata,
863
+ metadata = _videoComponent$metad === void 0 ? [] : _videoComponent$metad;
864
+ var videoMediaInfo = parseBaseMediaInfoType(mediaInfo);
865
+ var videoMetadata = parseKeyValuePairType(metadata);
866
+ var videoFormat = videoMediaInfo.Format,
867
+ timeBaseText = videoMediaInfo['Frame rate'],
868
+ colorSpace = videoMediaInfo['Color space'],
869
+ colorPrimaries = videoMediaInfo['Color primaries'],
870
+ chromaSubsampling = videoMediaInfo.Colorimetry;
871
+ var timeBase;
872
+ var averageFrameRate = videoComponent.averageFrameRate,
873
+ realBaseFrameRate = videoComponent.realBaseFrameRate;
927
874
 
928
- return round ? rate.toFixed(2) : rate;
929
- }
930
- }]);
875
+ if (realBaseFrameRate !== undefined) {
876
+ timeBase = {
877
+ numerator: realBaseFrameRate.denominator,
878
+ denominator: realBaseFrameRate.numerator
879
+ };
880
+ } else if (timeBaseText !== undefined) {
881
+ timeBase = formatTimeBaseText(timeBaseText);
882
+ } else if (averageFrameRate !== undefined) {
883
+ timeBase = {
884
+ numerator: averageFrameRate.denominator,
885
+ denominator: averageFrameRate.numerator
886
+ };
887
+ }
931
888
 
932
- return TimeBase;
933
- }();
889
+ var samples = videoMediaInfo['Frame count'];
934
890
 
935
- var isDropFrameTimeBase = function isDropFrameTimeBase(_ref3) {
936
- var numerator = _ref3.numerator,
937
- denominator = _ref3.denominator;
938
- return numerator === 1001 && (denominator === 60000 || denominator === 30000);
939
- };
891
+ if (samples === undefined) {
892
+ var numberOfPackets = videoComponent.numberOfPackets;
893
+ if (numberOfPackets !== undefined) samples = numberOfPackets;
894
+ }
940
895
 
941
- var TimeCode = /*#__PURE__*/function () {
942
- function TimeCode() {
943
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
944
- _ref4$samples = _ref4.samples,
945
- samples = _ref4$samples === void 0 ? 0 : _ref4$samples,
946
- timeBase = _ref4.timeBase;
896
+ var timeCode;
897
+ var frameRate;
898
+ var smpte;
947
899
 
948
- var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
949
- dropFrame = _ref5.dropFrame,
950
- _ref5$field = _ref5.field,
951
- field = _ref5$field === void 0 ? 2 : _ref5$field;
900
+ if (samples && timeBase) {
901
+ timeCode = formatTimeCodeType({
902
+ samples: samples,
903
+ timeBase: timeBase
904
+ });
905
+ frameRate = timeCode.timeBase.toRate(true);
906
+ smpte = timeCode.toSmpte(true);
907
+ }
952
908
 
953
- _classCallCheck(this, TimeCode);
909
+ var height = resolution.height,
910
+ width = resolution.width;
911
+ var aspectRatio = parseAspectRatio(resolution);
912
+ var dimension = "".concat(width, "x").concat(height);
913
+ var videoBitrate = bitrate ? parseFileSize__default["default"](bitrate, {
914
+ bits: true
915
+ }) : undefined;
916
+ return {
917
+ videoFormat: videoFormat,
918
+ dimension: dimension,
919
+ frameRate: frameRate,
920
+ height: height,
921
+ width: width,
922
+ timeBase: timeBase,
923
+ timeCode: timeCode,
924
+ videoCodec: videoCodec,
925
+ smpte: smpte,
926
+ videoBitrate: videoBitrate,
927
+ fieldOrder: fieldOrder,
928
+ colorSpace: colorSpace,
929
+ chromaSubsampling: chromaSubsampling,
930
+ aspectRatio: aspectRatio,
931
+ colorPrimaries: colorPrimaries,
932
+ videoMetadata: videoMetadata,
933
+ videoMediaInfo: videoMediaInfo
934
+ };
935
+ };
954
936
 
955
- if (typeof samples === 'number') {
956
- this.samples = samples;
957
- } else if (typeof samples === 'string') {
958
- if (samples === '-INF') {
959
- this.samples = -Infinity;
960
- } else if (samples === '+INF') {
961
- this.samples = Infinity;
962
- } else {
963
- this.samples = Number(samples);
964
- }
965
- } else {
966
- throw new Error("samples is not number/string/-Inf/+Inf is: ".concat(samples));
967
- }
937
+ var parseAudioComponent = function parseAudioComponent(audioComponent) {
938
+ var _audioComponent$timeB = audioComponent.timeBase,
939
+ timeBase = _audioComponent$timeB === void 0 ? {} : _audioComponent$timeB,
940
+ audioChannels = audioComponent.channelCount,
941
+ audioCodec = audioComponent.codec,
942
+ _audioComponent$media = audioComponent.mediaInfo,
943
+ mediaInfo = _audioComponent$media === void 0 ? {} : _audioComponent$media,
944
+ bitrate = audioComponent.bitrate,
945
+ _audioComponent$metad = audioComponent.metadata,
946
+ metadata = _audioComponent$metad === void 0 ? [] : _audioComponent$metad;
947
+ var audioMediaInfo = parseBaseMediaInfoType(mediaInfo);
948
+ var audioMetadata = parseKeyValuePairType(metadata);
949
+ var audioFormat = audioMediaInfo.Format,
950
+ audioBitDepth = audioMediaInfo.Resolution,
951
+ audioBitRateMode = audioMediaInfo.Bit_rate_mode;
952
+ var audioSamplerateSamples = timeBase.denominator ? timeBase.denominator / timeBase.numerator : undefined;
953
+ var audioSamplerate = audioSamplerateSamples ? parseFileSize__default["default"](audioSamplerateSamples, {
954
+ base: 10,
955
+ round: 1,
956
+ symbols: sampleRateSymbols
957
+ }) : undefined;
958
+ var audioBitrate = bitrate ? parseFileSize__default["default"](bitrate, {
959
+ base: 10,
960
+ round: 2,
961
+ symbols: bitRateSymbols
962
+ }) : undefined;
963
+ return {
964
+ audioFormat: audioFormat,
965
+ audioCodec: audioCodec,
966
+ audioSamplerate: audioSamplerate,
967
+ audioSamplerateSamples: audioSamplerateSamples,
968
+ audioBitDepth: audioBitDepth,
969
+ audioBitrate: audioBitrate,
970
+ audioBitRateMode: audioBitRateMode,
971
+ audioChannels: audioChannels,
972
+ audioMediaInfo: audioMediaInfo,
973
+ audioMetadata: audioMetadata
974
+ };
975
+ };
968
976
 
969
- this.timeBase = new TimeBase(timeBase);
970
- this.dropFrame = dropFrame === undefined ? isDropFrameTimeBase(this.timeBase) : dropFrame;
971
- this.field = field;
977
+ var parseBinaryComponent = function parseBinaryComponent(binaryComponent) {
978
+ var fileList = binaryComponent.file,
979
+ _binaryComponent$medi = binaryComponent.mediaInfo,
980
+ mediaInfo = _binaryComponent$medi === void 0 ? {} : _binaryComponent$medi,
981
+ _binaryComponent$meta = binaryComponent.metadata,
982
+ metadata = _binaryComponent$meta === void 0 ? [] : _binaryComponent$meta;
983
+ var binaryMetadata = parseKeyValuePairType(metadata);
984
+ var binaryMediaInfo = parseBaseMediaInfoType(mediaInfo);
985
+ var parsedBinaryComponent = {
986
+ binaryMetadata: binaryMetadata,
987
+ binaryMediaInfo: binaryMediaInfo
988
+ };
989
+
990
+ if (fileList) {
991
+ var _fileList2 = _slicedToArray__default["default"](fileList, 1),
992
+ fileType = _fileList2[0];
993
+
994
+ var parsedFileType = parseFileType(fileType);
995
+ parsedBinaryComponent = _objectSpread$6(_objectSpread$6({}, parsedBinaryComponent), parsedFileType);
972
996
  }
973
997
 
974
- _createClass(TimeCode, [{
975
- key: "add",
976
- value: function add(val) {
977
- var _val$timeBase = val.timeBase,
978
- numerator = _val$timeBase.numerator,
979
- denominator = _val$timeBase.denominator;
980
- var conformedTimeCode = val;
998
+ return parsedBinaryComponent;
999
+ };
981
1000
 
982
- if (numerator !== this.timeBase.numerator || denominator !== this.timeBase.denominator) {
983
- conformedTimeCode = val.conformTimeBase(this.timeBase);
984
- }
1001
+ var parseShapeType = function parseShapeType() {
1002
+ var shapeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1003
+ var parsedShape = {};
1004
+ var containerComponent = shapeType.containerComponent,
1005
+ videoComponentList = shapeType.videoComponent,
1006
+ audioComponentList = shapeType.audioComponent,
1007
+ binaryComponentList = shapeType.binaryComponent,
1008
+ _shapeType$mimeType = shapeType.mimeType,
1009
+ mimeTypeList = _shapeType$mimeType === void 0 ? [] : _shapeType$mimeType,
1010
+ _shapeType$tag = shapeType.tag,
1011
+ tagList = _shapeType$tag === void 0 ? [] : _shapeType$tag;
985
1012
 
986
- var _conformedTimeCode = conformedTimeCode,
987
- samples = _conformedTimeCode.samples;
988
- return new TimeCode({
989
- samples: this.samples + samples,
990
- timeBase: this.timeBase
991
- });
992
- }
993
- }, {
994
- key: "subtract",
995
- value: function subtract(val) {
996
- var _val$timeBase2 = val.timeBase,
997
- numerator = _val$timeBase2.numerator,
998
- denominator = _val$timeBase2.denominator;
999
- var conformedTimeCode = val;
1013
+ var _tagList = _slicedToArray__default["default"](tagList, 1);
1000
1014
 
1001
- if (numerator !== this.timeBase.numerator || denominator !== this.timeBase.denominator) {
1002
- conformedTimeCode = val.conformTimeBase(this.timeBase);
1003
- }
1015
+ parsedShape.tag = _tagList[0];
1004
1016
 
1005
- var _conformedTimeCode2 = conformedTimeCode,
1006
- samples = _conformedTimeCode2.samples;
1007
- return new TimeCode({
1008
- samples: this.samples - samples,
1009
- timeBase: this.timeBase
1010
- });
1011
- }
1012
- }, {
1013
- key: "conformTimeBase",
1014
- value: function conformTimeBase(conformTo) {
1015
- var timeBase = conformTo;
1017
+ var _mimeTypeList = _slicedToArray__default["default"](mimeTypeList, 1);
1016
1018
 
1017
- if (conformTo instanceof TimeCode === false) {
1018
- timeBase = new TimeBase(conformTo);
1019
- }
1019
+ parsedShape.mimeType = _mimeTypeList[0];
1020
1020
 
1021
- var samples = Math.round(this.samples / (this.timeBase.toRate(false, false) / timeBase.toRate(false, false)));
1022
- var timeCode = {
1023
- samples: samples,
1024
- timeBase: timeBase
1025
- };
1026
- return new TimeCode(timeCode);
1027
- }
1028
- }, {
1029
- key: "toJSON",
1030
- value: function toJSON() {
1031
- return {
1032
- samples: this.samples,
1033
- timeBase: this.timeBase
1034
- };
1035
- }
1036
- }, {
1037
- key: "toText",
1038
- value: function toText() {
1039
- var timeCodeText = String(this.samples);
1040
- var timeBaseText = this.timeBase.toText();
1021
+ if (containerComponent) {
1022
+ var parsedContainerComponent = parseContainerComponent(containerComponent);
1023
+ parsedShape = _objectSpread$6(_objectSpread$6({}, parsedShape), parsedContainerComponent);
1024
+ }
1041
1025
 
1042
- if (timeBaseText !== '1') {
1043
- timeCodeText = [this.samples, timeBaseText].join('@');
1044
- }
1026
+ if (videoComponentList) {
1027
+ var _videoComponentList = _slicedToArray__default["default"](videoComponentList, 1),
1028
+ videoComponent = _videoComponentList[0];
1045
1029
 
1046
- return timeCodeText;
1047
- }
1048
- }, {
1049
- key: "toSeconds",
1050
- value: function toSeconds() {
1051
- var _this$timeBase = this.timeBase,
1052
- numerator = _this$timeBase.numerator,
1053
- denominator = _this$timeBase.denominator;
1054
- return this.samples * (numerator / denominator);
1055
- }
1056
- }, {
1057
- key: "toTime",
1058
- value: function toTime() {
1059
- var roundedFrameRate = getRoundedFrameRate(this.timeBase);
1060
- var totalSamples = this.samples + (this.dropFrame ? countDroppedFrames(this.samples + 1, roundedFrameRate) : 0);
1061
- var hours = Math.floor(totalSamples / (3600 * roundedFrameRate));
1062
- var minutes = Math.floor(totalSamples / (60 * roundedFrameRate)) % 60;
1063
- var seconds = Math.floor(totalSamples / roundedFrameRate) % 60;
1064
- var frames = totalSamples % roundedFrameRate;
1065
- var partialSeconds = frames / roundedFrameRate;
1066
- return {
1067
- hours: hours,
1068
- minutes: minutes,
1069
- seconds: seconds,
1070
- frames: frames,
1071
- partialSeconds: partialSeconds
1072
- };
1073
- }
1074
- }, {
1075
- key: "toDuration",
1076
- value: function toDuration() {
1077
- var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1078
- format = _ref6.format;
1030
+ var parsedVideoComponent = parseVideoComponent(videoComponent);
1031
+ parsedShape = _objectSpread$6(_objectSpread$6({}, parsedShape), parsedVideoComponent);
1032
+ }
1079
1033
 
1080
- var _this$toTime = this.toTime(),
1081
- hours = _this$toTime.hours,
1082
- minutes = _this$toTime.minutes,
1083
- seconds = _this$toTime.seconds;
1034
+ if (audioComponentList) {
1035
+ var _audioComponentList = _slicedToArray__default["default"](audioComponentList, 1),
1036
+ audioComponent = _audioComponentList[0];
1084
1037
 
1085
- if (typeof format === 'string') {
1086
- if (format.toLowerCase() === 'hhmmss') {
1087
- return [hours.toFixed().padStart(2, '0'), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
1088
- }
1089
- }
1038
+ var parsedAudioComponent = parseAudioComponent(audioComponent);
1039
+ parsedShape = _objectSpread$6(_objectSpread$6({}, parsedShape), parsedAudioComponent);
1040
+ }
1090
1041
 
1091
- if (hours) {
1092
- return [hours.toFixed(), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
1093
- }
1042
+ if (binaryComponentList) {
1043
+ var _binaryComponentList = _slicedToArray__default["default"](binaryComponentList, 1),
1044
+ binaryComponent = _binaryComponentList[0];
1094
1045
 
1095
- if (minutes >= 10) {
1096
- return [minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
1097
- }
1046
+ var parsedBinaryComponent = parseBinaryComponent(binaryComponent);
1047
+ parsedShape = _objectSpread$6(_objectSpread$6({}, parsedShape), parsedBinaryComponent);
1048
+ }
1098
1049
 
1099
- return [minutes.toFixed(), seconds.toFixed().padStart(2, '0')].join(':');
1100
- }
1101
- }, {
1102
- key: "toSmpte",
1103
- value: function toSmpte() {
1104
- var _this2 = this;
1050
+ return parsedShape;
1051
+ };
1105
1052
 
1106
- if (this.samples === -Infinity) return '00:00:00:00';
1053
+ var _excluded$3 = ["Codec"],
1054
+ _excluded2$2 = ["Codec"];
1107
1055
 
1108
- var _this$toTime2 = this.toTime(),
1109
- hours = _this$toTime2.hours,
1110
- minutes = _this$toTime2.minutes,
1111
- seconds = _this$toTime2.seconds,
1112
- frames = _this$toTime2.frames;
1056
+ var parseMediaConvertPreset = function parseMediaConvertPreset(transcodePresetType) {
1057
+ var output = {};
1058
+ var description = transcodePresetType.description,
1059
+ _transcodePresetType$ = transcodePresetType.mediaconvert;
1060
+ _transcodePresetType$ = _transcodePresetType$ === void 0 ? {} : _transcodePresetType$;
1061
+ var _transcodePresetType$2 = _transcodePresetType$.outputSetting,
1062
+ outputSetting = _transcodePresetType$2 === void 0 ? [] : _transcodePresetType$2;
1063
+ output.description = description;
1064
+ if (outputSetting.length === 0) return output;
1065
+ var mc = JSON.parse(outputSetting[0]);
1066
+ var _mc$Settings = mc.Settings;
1067
+ _mc$Settings = _mc$Settings === void 0 ? {} : _mc$Settings;
1068
+ var ContainerSettings = _mc$Settings.ContainerSettings,
1069
+ VideoDescription = _mc$Settings.VideoDescription,
1070
+ AudioDescriptions = _mc$Settings.AudioDescriptions;
1071
+ output.containerFormat = ContainerSettings.Container;
1113
1072
 
1114
- var hhmmss = [hours.toFixed().padStart(2, '0'), minutes.toFixed().padStart(2, '0'), seconds.toFixed().padStart(2, '0')].join(':');
1073
+ if (ContainerSettings) {
1074
+ output.containerFormat = ContainerSettings.Container;
1075
+ }
1115
1076
 
1116
- var _Object$entries$find = Object.entries(FRAME_SEPARATORS).find(function (thisSeparator) {
1117
- var _thisSeparator = _slicedToArray(thisSeparator, 2),
1118
- _thisSeparator$ = _thisSeparator[1],
1119
- dropFrame = _thisSeparator$.dropFrame,
1120
- field = _thisSeparator$.field;
1077
+ if (VideoDescription) {
1078
+ var _VideoDescription$Cod = VideoDescription.CodecSettings,
1079
+ CodecSettings = _VideoDescription$Cod === void 0 ? {} : _VideoDescription$Cod;
1121
1080
 
1122
- return dropFrame === _this2.dropFrame && field === _this2.field;
1123
- }),
1124
- _Object$entries$find2 = _slicedToArray(_Object$entries$find, 1),
1125
- _Object$entries$find3 = _Object$entries$find2[0],
1126
- frameSeparator = _Object$entries$find3 === void 0 ? ':' : _Object$entries$find3;
1081
+ var Codec = CodecSettings.Codec,
1082
+ otherSettings = _objectWithoutProperties__default["default"](CodecSettings, _excluded$3);
1127
1083
 
1128
- return [hhmmss, frames.toFixed().padStart(2, '0')].join(frameSeparator);
1129
- }
1130
- }, {
1131
- key: "toFraction",
1132
- value: function toFraction() {
1133
- return "".concat(this.samples, "@").concat(this.timeBase.denominator, ":").concat(this.timeBase.numerator);
1134
- }
1135
- }]);
1084
+ output.videoFormat = Codec;
1085
+ var height = VideoDescription.Height,
1086
+ width = VideoDescription.Width;
1087
+ output.height = height;
1088
+ output.width = width;
1136
1089
 
1137
- return TimeCode;
1138
- }();
1090
+ if (height && width) {
1091
+ output.dimension = "".concat(width, "x").concat(height);
1092
+ output.aspectRatio = parseAspectRatio({
1093
+ height: height,
1094
+ width: width
1095
+ });
1096
+ }
1139
1097
 
1140
- var formatTimeBaseType = function formatTimeBaseType(timeBase) {
1141
- return new TimeBase(timeBase);
1142
- };
1098
+ var _Object$values = Object.values(otherSettings),
1099
+ _Object$values2 = _slicedToArray__default["default"](_Object$values, 1),
1100
+ codecSpecs = _Object$values2[0];
1143
1101
 
1144
- var formatTimeBaseText = function formatTimeBaseText(timeBaseText) {
1145
- if (timeBaseText === undefined) {
1146
- return formatTimeBaseType();
1147
- }
1102
+ if (codecSpecs) {
1103
+ output.fieldOrder = codecSpecs.InterlaceMode;
1104
+ if (output.fieldOrder && output.fieldOrder.includes('TOP')) output.fieldOrder = 'interlaced';
1105
+ output.videoBitrate = codecSpecs.Bitrate;
1106
+ var numerator = codecSpecs.FramerateDenominator; // other way round to vs ¯\_(ツ)_/¯
1148
1107
 
1149
- if (typeof timeBaseText === 'number') {
1150
- return formatTimeBaseType({
1151
- denominator: timeBaseText
1152
- });
1108
+ var denominator = codecSpecs.FramerateNumerator;
1109
+ var timeBase = formatTimeBaseType({
1110
+ denominator: denominator,
1111
+ numerator: numerator
1112
+ });
1113
+ output.timeBase = timeBase;
1114
+ output.frameRate = timeBase.toRate(true);
1115
+ }
1153
1116
  }
1154
1117
 
1155
- if (timeBaseText.includes(':')) {
1156
- var _timeBaseText$split = timeBaseText.split(':'),
1157
- _timeBaseText$split2 = _slicedToArray(_timeBaseText$split, 2),
1158
- _denominator = _timeBaseText$split2[0],
1159
- numerator = _timeBaseText$split2[1];
1118
+ if (AudioDescriptions && AudioDescriptions.length > 0) {
1119
+ var _AudioDescriptions$0$ = AudioDescriptions[0].CodecSettings,
1120
+ _CodecSettings = _AudioDescriptions$0$ === void 0 ? {} : _AudioDescriptions$0$;
1160
1121
 
1161
- return formatTimeBaseType({
1162
- denominator: _denominator,
1163
- numerator: numerator
1164
- });
1165
- }
1122
+ var _Codec = _CodecSettings.Codec,
1123
+ _otherSettings = _objectWithoutProperties__default["default"](_CodecSettings, _excluded2$2);
1166
1124
 
1167
- if (Object.keys(CONSTANT_TIMEBASES).includes(timeBaseText)) {
1168
- return formatTimeBaseType(CONSTANT_TIMEBASES[timeBaseText]);
1169
- }
1125
+ output.audioFormat = _Codec;
1170
1126
 
1171
- var denominator = Number(timeBaseText);
1127
+ var _Object$values3 = Object.values(_otherSettings),
1128
+ _Object$values4 = _slicedToArray__default["default"](_Object$values3, 1),
1129
+ _codecSpecs = _Object$values4[0];
1172
1130
 
1173
- if (Number.isNaN(denominator)) {
1174
- throw new Error("timeBaseText must be a number or ".concat(Object.keys(CONSTANT_TIMEBASES).join(','), " - is ").concat(timeBaseText));
1131
+ if (_codecSpecs) {
1132
+ output.audioSamplerate = _codecSpecs.SampleRate;
1133
+ output.audioBitrate = _codecSpecs.Bitrate;
1134
+ output.audioBitRateMode = _codecSpecs.RateControlMode;
1135
+ }
1175
1136
  }
1176
1137
 
1177
- return formatTimeBaseType({
1178
- denominator: denominator
1179
- });
1138
+ return output;
1180
1139
  };
1181
1140
 
1182
- var formatTimeBase = function formatTimeBase(timeBase) {
1183
- if (_typeof(timeBase) === 'object') {
1184
- return formatTimeBaseType(timeBase);
1185
- }
1141
+ var parseTranscodePreset = function parseTranscodePreset(transcodePresetType) {
1142
+ var output = {};
1143
+ var description = transcodePresetType.description,
1144
+ format = transcodePresetType.format,
1145
+ audio = transcodePresetType.audio,
1146
+ video = transcodePresetType.video,
1147
+ mediaconvert = transcodePresetType.mediaconvert;
1148
+ if (mediaconvert) return parseMediaConvertPreset(transcodePresetType);
1149
+ output.description = description;
1150
+ output.containerFormat = format;
1186
1151
 
1187
- return formatTimeBaseText(timeBase);
1188
- };
1152
+ if (video) {
1153
+ output.videoFormat = video.codec;
1154
+ output.videoBitrate = video.bitrate;
1189
1155
 
1190
- var formatTimeCodeType = function formatTimeCodeType(timeCode, options) {
1191
- return new TimeCode(timeCode, options);
1192
- };
1156
+ if (video.framerate) {
1157
+ var timeBase = formatTimeBaseType(video.framerate);
1158
+ output.timeBase = timeBase;
1159
+ output.frameRate = timeBase.toRate(true);
1160
+ }
1193
1161
 
1194
- var formatTimeCodeText = function formatTimeCodeText(timeCodeText, options) {
1195
- if (timeCodeText === undefined) {
1196
- var _timeCode = {
1197
- samples: 0
1198
- };
1199
- return formatTimeCodeType(_timeCode, options);
1162
+ if (video.scaling) {
1163
+ var _video$scaling = video.scaling,
1164
+ height = _video$scaling.height,
1165
+ width = _video$scaling.width;
1166
+ output.height = height;
1167
+ output.width = width;
1168
+
1169
+ if (height && width) {
1170
+ output.dimension = "".concat(width, "x").concat(height);
1171
+ output.aspectRatio = parseAspectRatio({
1172
+ height: height,
1173
+ width: width
1174
+ });
1175
+ }
1176
+ }
1200
1177
  }
1201
1178
 
1202
- if (typeof timeCodeText === 'number') {
1203
- var _timeCode2 = {
1204
- samples: timeCodeText
1205
- };
1206
- return formatTimeCodeType(_timeCode2, options);
1207
- }
1208
-
1209
- if (timeCodeText.includes('@')) {
1210
- var _timeCodeText$split = timeCodeText.split('@'),
1211
- _timeCodeText$split2 = _slicedToArray(_timeCodeText$split, 2),
1212
- samplesString = _timeCodeText$split2[0],
1213
- timeBaseText = _timeCodeText$split2[1];
1214
-
1215
- var _samples = Number(samplesString);
1216
-
1217
- var timeBase = formatTimeBaseText(timeBaseText);
1218
- var _timeCode3 = {
1219
- samples: _samples,
1220
- timeBase: timeBase
1221
- };
1222
- return formatTimeCodeType(_timeCode3, options);
1223
- }
1224
-
1225
- if (timeCodeText === '-INF') {
1226
- var _samples2 = -Infinity;
1227
-
1228
- var _timeCode4 = {
1229
- samples: _samples2
1230
- };
1231
- return formatTimeCodeType(_timeCode4, options);
1232
- }
1233
-
1234
- if (timeCodeText === '+INF') {
1235
- var _samples3 = Infinity;
1236
- var _timeCode5 = {
1237
- samples: _samples3
1238
- };
1239
- return formatTimeCodeType(_timeCode5, options);
1240
- }
1241
-
1242
- var samples = Number(timeCodeText);
1243
-
1244
- if (Number.isNaN(samples)) {
1245
- throw new Error("timeBaseText must be a number or sample@timeBase - is ".concat(timeCodeText));
1246
- }
1247
-
1248
- var timeCode = {
1249
- samples: samples
1250
- };
1251
- return formatTimeCodeType(timeCode, options);
1252
- };
1253
-
1254
- var formatSeconds = function formatSeconds(seconds) {
1255
- var timeBase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1256
- var options = arguments.length > 2 ? arguments[2] : undefined;
1257
-
1258
- if (Number.isNaN(Number(seconds))) {
1259
- throw new Error("seconds must be digits, is ".concat(seconds));
1260
- }
1261
-
1262
- var _timeBase$denominator = timeBase.denominator,
1263
- denominator = _timeBase$denominator === void 0 ? 1 : _timeBase$denominator,
1264
- _timeBase$numerator = timeBase.numerator,
1265
- numerator = _timeBase$numerator === void 0 ? 1 : _timeBase$numerator;
1266
- var samples = seconds * (denominator / numerator);
1267
- var timeCode = {
1268
- samples: samples,
1269
- timeBase: timeBase
1270
- };
1271
- return new TimeCode(timeCode, options);
1272
- };
1273
-
1274
- var formatSecondsPrecise = function formatSecondsPrecise(seconds) {
1275
- var timeBase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1276
- var options = arguments.length > 2 ? arguments[2] : undefined;
1277
-
1278
- if (Number.isNaN(Number(seconds))) {
1279
- throw new Error("seconds must be digits, is ".concat(seconds));
1280
- }
1281
-
1282
- var _timeBase$numerator2 = timeBase.numerator,
1283
- numerator = _timeBase$numerator2 === void 0 ? 1 : _timeBase$numerator2;
1284
- var _timeBase$denominator2 = timeBase.denominator,
1285
- denominator = _timeBase$denominator2 === void 0 ? 1 : _timeBase$denominator2;
1286
-
1287
- if (!Number.isInteger(seconds)) {
1288
- var decimalPlaces = String(seconds).split('.')[1].length;
1289
- denominator *= Math.pow(10, decimalPlaces);
1179
+ if (audio) {
1180
+ var audioFormat = audio.codec,
1181
+ channel = audio.channel;
1182
+ output.audioFormat = audioFormat;
1183
+ if (channel) output.audioChannels = channel.length;
1290
1184
  }
1291
1185
 
1292
- var samples = (seconds * (denominator / numerator)).toFixed();
1293
- var timeCode = {
1294
- samples: samples,
1295
- timeBase: {
1296
- denominator: denominator,
1297
- numerator: numerator
1298
- }
1299
- };
1300
- return new TimeCode(timeCode, options);
1186
+ return output;
1301
1187
  };
1302
1188
 
1303
- var formatSmpte = function formatSmpte(smpteText, timeBaseText) {
1304
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1305
-
1306
- if (smpteText === undefined) {
1307
- var _timeBase = formatTimeBase(timeBaseText);
1308
-
1309
- var _timeCode6 = {
1310
- samples: 0,
1311
- timeBase: _timeBase
1312
- };
1313
- return formatTimeCodeType(_timeCode6);
1314
- }
1315
-
1316
- if (typeof smpteText !== 'string') {
1317
- throw new Error("smpteText must be a string, is ".concat(smpteText));
1318
- }
1319
-
1320
- var _splitSmpte = splitSmpte(smpteText),
1321
- _splitSmpte2 = _slicedToArray(_splitSmpte, 2),
1322
- _splitSmpte2$ = _slicedToArray(_splitSmpte2[0], 4),
1323
- hh = _splitSmpte2$[0],
1324
- mm = _splitSmpte2$[1],
1325
- ss = _splitSmpte2$[2],
1326
- _splitSmpte2$$ = _splitSmpte2$[3],
1327
- ff = _splitSmpte2$$ === void 0 ? 0 : _splitSmpte2$$,
1328
- frameOptions = _splitSmpte2[1];
1329
-
1330
- var _frameOptions$dropFra = frameOptions.dropFrame,
1331
- dropFrame = _frameOptions$dropFra === void 0 ? false : _frameOptions$dropFra;
1332
- var timeBase = formatTimeBase(timeBaseText);
1333
- var roundedFrameRate = getRoundedFrameRate(timeBase);
1334
-
1335
- if (mm >= 60 || mm < 0 || ss >= 60 || ss < 0 || ff >= roundedFrameRate || ff < 0) {
1336
- throw new Error('Invalid mm, ss or ff');
1337
- }
1338
-
1339
- var samples = countSamples(hh, mm, ss, ff, {
1340
- dropFrame: dropFrame,
1341
- roundedFrameRate: roundedFrameRate
1342
- });
1343
- var timeCode = {
1344
- samples: samples,
1345
- timeBase: timeBase
1346
- };
1347
- return formatTimeCodeType(timeCode, _objectSpread2(_objectSpread2({}, frameOptions), options));
1189
+ var PDF = 'PDF';
1190
+ var TEXT = 'TEXT';
1191
+ var MSWORD = 'MSWORD';
1192
+ var JSON$1 = 'JSON';
1193
+ var XML = 'XML';
1194
+ var getDocumentType = function getDocumentType() {
1195
+ var shape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1196
+ var mimeType = shape.mimeType;
1197
+ if (!mimeType) return undefined;
1198
+ if (mimeType.endsWith('/pdf')) return PDF;
1199
+ if (mimeType.startsWith('text/')) return TEXT;
1200
+ if (mimeType.endsWith('/msword')) return MSWORD;
1201
+ if (mimeType.endsWith('/json')) return JSON$1;
1202
+ if (mimeType.endsWith('/xml')) return XML;
1203
+ return undefined;
1348
1204
  };
1349
1205
 
1350
- var parseKeyValuePairType = function parseKeyValuePairType() {
1351
- var keyValuePairType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1206
+ var ACCESSCONTROL_READ = '_accesscontrol_read';
1207
+ var ACCESSCONTROL_WRITE = '_accesscontrol_write';
1208
+ var ADMINISTRATOR = '_administrator';
1209
+ var AUTO_PROJECTION_READ = '_auto_projection_read';
1210
+ var AUTO_PROJECTION_WRITE = '_auto_projection_write';
1211
+ var COLLECTION_NOTIFICATION_READ = '_collection_notification_read';
1212
+ var COLLECTION_NOTIFICATION_WRITE = '_collection_notification_write';
1213
+ var COLLECTION_READ = '_collection_read';
1214
+ var COLLECTION_WRITE = '_collection_write';
1215
+ var DELETION_LOCK_NOTIFICATION_READ = '_deletion_lock_notification_read';
1216
+ var DELETION_LOCK_NOTIFICATION_WRITE = '_deletion_lock_notification_write';
1217
+ var DELETION_LOCK_READ = '_deletion_lock_read';
1218
+ var DELETION_LOCK_WRITE = '_deletion_lock_write';
1219
+ var DOCUMENT_NOTIFICATION_READ = '_document_notification_read';
1220
+ var DOCUMENT_NOTIFICATION_WRITE = '_document_notification_write';
1221
+ var DOCUMENT_READ = '_document_read';
1222
+ var DOCUMENT_WRITE = '_document_write';
1223
+ var ERROR_READ = '_error_read';
1224
+ var ERROR_WRITE = '_error_write';
1225
+ var EXPORT = '_export';
1226
+ var EXPORT_TEMPLATE_READ = '_export_template_read';
1227
+ var EXPORT_TEMPLATE_WRITE = '_export_template_write';
1228
+ var EXTERNAL_ID_READ = '_external_id_read';
1229
+ var EXTERNAL_ID_WRITE = '_external_id_write';
1230
+ var FILE_NOTIFICATION_READ = '_file_notification_read';
1231
+ var FILE_NOTIFICATION_WRITE = '_file_notification_write';
1232
+ var FILE_READ = '_file_read';
1233
+ var FILE_WRITE = '_file_write';
1234
+ var GROUP_READ = '_group_read';
1235
+ var GROUP_WRITE = '_group_write';
1236
+ var IMPORT_WRITE = '_import';
1237
+ var ITEM_ID_READ = '_item_id_read';
1238
+ var ITEM_ID_WRITE = '_item_id_write';
1239
+ var ITEM_NOTIFICATION_READ = '_item_notification_read';
1240
+ var ITEM_NOTIFICATION_WRITE = '_item_notification_write';
1241
+ var ITEM_WRITE = '_item_write';
1242
+ var ITEM_SEARCH = '_item_search';
1243
+ var ITEM_SHAPE_READ = '_item_shape_read';
1244
+ var ITEM_SHAPE_WRITE = '_item_shape_write';
1245
+ var ITEM_TIMELINE_READ = '_item_timeline_read';
1246
+ var ITEM_TIMELINE_WRITE = '_item_timeline_write';
1247
+ var ITEM_URI = '_item_uri';
1248
+ var JOB_NOTIFICATION_READ = '_job_notification_read';
1249
+ var JOB_NOTIFICATION_WRITE = '_job_notification_write';
1250
+ var JOB_READ = '_job_read';
1251
+ var JOB_WRITE = '_job_write';
1252
+ var LIBRARY_READ = '_library_read';
1253
+ var LIBRARY_WRITE = '_library_write';
1254
+ var LOCK_READ = '_lock_read';
1255
+ var LOCK_WRITE = '_lock_write';
1256
+ var LOG_READ = '_log_read';
1257
+ var METADATA_DATASET_READ = '_metadata_dataset_read';
1258
+ var METADATA_DATASET_WRITE = '_metadata_dataset_write';
1259
+ var METADATA_FIELD_GROUP_READ = '_metadata_field_group_read';
1260
+ var METADATA_FIELD_GROUP_WRITE = '_metadata_field_group_write';
1261
+ var METADATA_FIELD_READ = '_metadata_field_read';
1262
+ var METADATA_FIELD_WRITE = '_metadata_field_write';
1263
+ var METADATA_GLOBAL_READ = '_metadata_global_read';
1264
+ var METADATA_GLOBAL_WRITE = '_metadata_global_write';
1265
+ var METADATA_LOCK_READ = '_metadata_lock_read';
1266
+ var METADATA_LOCK_WRITE = '_metadata_lock_write';
1267
+ var METADATA_READ = '_metadata_read';
1268
+ var METADATA_SCHEMA_READ = '_metadata_schema_read';
1269
+ var METADATA_SCHEMA_WRITE = '_metadata_schema_write';
1270
+ var METADATA_WRITE = '_metadata_write';
1271
+ var OTIF_ANALYZE = '_otif_analyze';
1272
+ var OTIF_READ = '_otif_read';
1273
+ var OTIF_WRITE = '_otif_write';
1274
+ var PLACEHOLDER_NOTIFICATION_READ = '_placeholder_notification_read';
1275
+ var PLACEHOLDER_NOTIFICATION_WRITE = '_placeholder_notification_write';
1276
+ var PROJECTION_READ = '_projection_read';
1277
+ var PROJECTION_WRITE = '_projection_write';
1278
+ var QUOTA_NOTIFICATION_READ = '_quota_notification_read';
1279
+ var QUOTA_NOTIFICATION_WRITE = '_quota_notification_write';
1280
+ var QUOTA_READ = '_quota_read';
1281
+ var QUOTA_WRITE = '_quota_write';
1282
+ var RELATION_READ = '_relation_read';
1283
+ var RELATION_WRITE = '_relation_write';
1284
+ var RESOURCE_READ = '_resource_read';
1285
+ var RESOURCE_WRITE = '_resource_write';
1286
+ var RUN_AS = '_run_as';
1287
+ var SEARCH = '_search';
1288
+ var SEQUENCE_READ = '_sequence_read';
1289
+ var SEQUENCE_WRITE = '_sequence_write';
1290
+ var SHAPE_TAG_READ = '_shape_tag_read';
1291
+ var SHAPE_TAG_WRITE = '_shape_tag_write';
1292
+ var SITE_MANAGER = '_site_manager';
1293
+ var SITE_RULE_READ = '_site_rule_read';
1294
+ var SITE_RULE_WRITE = '_site_rule_write';
1295
+ var STORAGE_GROUP_READ = '_storage_group_read';
1296
+ var STORAGE_GROUP_WRITE = '_storage_group_write';
1297
+ var STORAGE_NOTIFICATION_READ = '_storage_notification_read';
1298
+ var STORAGE_NOTIFICATION_WRITE = '_storage_notification_write';
1299
+ var STORAGE_READ = '_storage_read';
1300
+ var STORAGE_RULE_READ = '_storage_rule_read';
1301
+ var STORAGE_RULE_WRITE = '_storage_rule_write';
1302
+ var STORAGE_WRITE = '_storage_write';
1303
+ var SUPER_ACCESS_USER = '_super_access_user';
1304
+ var TASKDEFINITION_READ = '_taskdefinition_read';
1305
+ var TASKDEFINITION_WRITE = '_taskdefinition_write';
1306
+ var THUMBNAIL_READ = '_thumbnail_read';
1307
+ var THUMBNAIL_WRITE = '_thumbnail_write';
1308
+ var TRANSCODER = '_transcoder';
1309
+ var TRANSFER_READ = '_transfer_read';
1310
+ var TRANSFER_WRITE = '_transfer_write';
1311
+ var USER = '_user';
1312
+ var VXA = '_vxa';
1313
+ var VXA_READ = '_vxa_read';
1352
1314
 
1353
- var keyValuePairTypeReducer = function keyValuePairTypeReducer(a, _ref) {
1354
- var key = _ref.key,
1355
- value = _ref.value;
1356
- return _objectSpread2(_objectSpread2({}, a), {}, _defineProperty({}, key, value));
1357
- };
1358
-
1359
- return keyValuePairType.reduce(keyValuePairTypeReducer, {});
1360
- };
1361
-
1362
- var sampleRateSymbols = {
1363
- kB: 'kHz',
1364
- B: 'Hz',
1365
- mB: 'mHz'
1366
- };
1367
- var bitRateSymbols = {
1368
- kB: 'kbps',
1369
- B: 'bps',
1370
- MB: 'mbps'
1371
- };
1315
+ var roles = /*#__PURE__*/Object.freeze({
1316
+ __proto__: null,
1317
+ ACCESSCONTROL_READ: ACCESSCONTROL_READ,
1318
+ ACCESSCONTROL_WRITE: ACCESSCONTROL_WRITE,
1319
+ ADMINISTRATOR: ADMINISTRATOR,
1320
+ AUTO_PROJECTION_READ: AUTO_PROJECTION_READ,
1321
+ AUTO_PROJECTION_WRITE: AUTO_PROJECTION_WRITE,
1322
+ COLLECTION_NOTIFICATION_READ: COLLECTION_NOTIFICATION_READ,
1323
+ COLLECTION_NOTIFICATION_WRITE: COLLECTION_NOTIFICATION_WRITE,
1324
+ COLLECTION_READ: COLLECTION_READ,
1325
+ COLLECTION_WRITE: COLLECTION_WRITE,
1326
+ DELETION_LOCK_NOTIFICATION_READ: DELETION_LOCK_NOTIFICATION_READ,
1327
+ DELETION_LOCK_NOTIFICATION_WRITE: DELETION_LOCK_NOTIFICATION_WRITE,
1328
+ DELETION_LOCK_READ: DELETION_LOCK_READ,
1329
+ DELETION_LOCK_WRITE: DELETION_LOCK_WRITE,
1330
+ DOCUMENT_NOTIFICATION_READ: DOCUMENT_NOTIFICATION_READ,
1331
+ DOCUMENT_NOTIFICATION_WRITE: DOCUMENT_NOTIFICATION_WRITE,
1332
+ DOCUMENT_READ: DOCUMENT_READ,
1333
+ DOCUMENT_WRITE: DOCUMENT_WRITE,
1334
+ ERROR_READ: ERROR_READ,
1335
+ ERROR_WRITE: ERROR_WRITE,
1336
+ EXPORT: EXPORT,
1337
+ EXPORT_TEMPLATE_READ: EXPORT_TEMPLATE_READ,
1338
+ EXPORT_TEMPLATE_WRITE: EXPORT_TEMPLATE_WRITE,
1339
+ EXTERNAL_ID_READ: EXTERNAL_ID_READ,
1340
+ EXTERNAL_ID_WRITE: EXTERNAL_ID_WRITE,
1341
+ FILE_NOTIFICATION_READ: FILE_NOTIFICATION_READ,
1342
+ FILE_NOTIFICATION_WRITE: FILE_NOTIFICATION_WRITE,
1343
+ FILE_READ: FILE_READ,
1344
+ FILE_WRITE: FILE_WRITE,
1345
+ GROUP_READ: GROUP_READ,
1346
+ GROUP_WRITE: GROUP_WRITE,
1347
+ IMPORT_WRITE: IMPORT_WRITE,
1348
+ ITEM_ID_READ: ITEM_ID_READ,
1349
+ ITEM_ID_WRITE: ITEM_ID_WRITE,
1350
+ ITEM_NOTIFICATION_READ: ITEM_NOTIFICATION_READ,
1351
+ ITEM_NOTIFICATION_WRITE: ITEM_NOTIFICATION_WRITE,
1352
+ ITEM_WRITE: ITEM_WRITE,
1353
+ ITEM_SEARCH: ITEM_SEARCH,
1354
+ ITEM_SHAPE_READ: ITEM_SHAPE_READ,
1355
+ ITEM_SHAPE_WRITE: ITEM_SHAPE_WRITE,
1356
+ ITEM_TIMELINE_READ: ITEM_TIMELINE_READ,
1357
+ ITEM_TIMELINE_WRITE: ITEM_TIMELINE_WRITE,
1358
+ ITEM_URI: ITEM_URI,
1359
+ JOB_NOTIFICATION_READ: JOB_NOTIFICATION_READ,
1360
+ JOB_NOTIFICATION_WRITE: JOB_NOTIFICATION_WRITE,
1361
+ JOB_READ: JOB_READ,
1362
+ JOB_WRITE: JOB_WRITE,
1363
+ LIBRARY_READ: LIBRARY_READ,
1364
+ LIBRARY_WRITE: LIBRARY_WRITE,
1365
+ LOCK_READ: LOCK_READ,
1366
+ LOCK_WRITE: LOCK_WRITE,
1367
+ LOG_READ: LOG_READ,
1368
+ METADATA_DATASET_READ: METADATA_DATASET_READ,
1369
+ METADATA_DATASET_WRITE: METADATA_DATASET_WRITE,
1370
+ METADATA_FIELD_GROUP_READ: METADATA_FIELD_GROUP_READ,
1371
+ METADATA_FIELD_GROUP_WRITE: METADATA_FIELD_GROUP_WRITE,
1372
+ METADATA_FIELD_READ: METADATA_FIELD_READ,
1373
+ METADATA_FIELD_WRITE: METADATA_FIELD_WRITE,
1374
+ METADATA_GLOBAL_READ: METADATA_GLOBAL_READ,
1375
+ METADATA_GLOBAL_WRITE: METADATA_GLOBAL_WRITE,
1376
+ METADATA_LOCK_READ: METADATA_LOCK_READ,
1377
+ METADATA_LOCK_WRITE: METADATA_LOCK_WRITE,
1378
+ METADATA_READ: METADATA_READ,
1379
+ METADATA_SCHEMA_READ: METADATA_SCHEMA_READ,
1380
+ METADATA_SCHEMA_WRITE: METADATA_SCHEMA_WRITE,
1381
+ METADATA_WRITE: METADATA_WRITE,
1382
+ OTIF_ANALYZE: OTIF_ANALYZE,
1383
+ OTIF_READ: OTIF_READ,
1384
+ OTIF_WRITE: OTIF_WRITE,
1385
+ PLACEHOLDER_NOTIFICATION_READ: PLACEHOLDER_NOTIFICATION_READ,
1386
+ PLACEHOLDER_NOTIFICATION_WRITE: PLACEHOLDER_NOTIFICATION_WRITE,
1387
+ PROJECTION_READ: PROJECTION_READ,
1388
+ PROJECTION_WRITE: PROJECTION_WRITE,
1389
+ QUOTA_NOTIFICATION_READ: QUOTA_NOTIFICATION_READ,
1390
+ QUOTA_NOTIFICATION_WRITE: QUOTA_NOTIFICATION_WRITE,
1391
+ QUOTA_READ: QUOTA_READ,
1392
+ QUOTA_WRITE: QUOTA_WRITE,
1393
+ RELATION_READ: RELATION_READ,
1394
+ RELATION_WRITE: RELATION_WRITE,
1395
+ RESOURCE_READ: RESOURCE_READ,
1396
+ RESOURCE_WRITE: RESOURCE_WRITE,
1397
+ RUN_AS: RUN_AS,
1398
+ SEARCH: SEARCH,
1399
+ SEQUENCE_READ: SEQUENCE_READ,
1400
+ SEQUENCE_WRITE: SEQUENCE_WRITE,
1401
+ SHAPE_TAG_READ: SHAPE_TAG_READ,
1402
+ SHAPE_TAG_WRITE: SHAPE_TAG_WRITE,
1403
+ SITE_MANAGER: SITE_MANAGER,
1404
+ SITE_RULE_READ: SITE_RULE_READ,
1405
+ SITE_RULE_WRITE: SITE_RULE_WRITE,
1406
+ STORAGE_GROUP_READ: STORAGE_GROUP_READ,
1407
+ STORAGE_GROUP_WRITE: STORAGE_GROUP_WRITE,
1408
+ STORAGE_NOTIFICATION_READ: STORAGE_NOTIFICATION_READ,
1409
+ STORAGE_NOTIFICATION_WRITE: STORAGE_NOTIFICATION_WRITE,
1410
+ STORAGE_READ: STORAGE_READ,
1411
+ STORAGE_RULE_READ: STORAGE_RULE_READ,
1412
+ STORAGE_RULE_WRITE: STORAGE_RULE_WRITE,
1413
+ STORAGE_WRITE: STORAGE_WRITE,
1414
+ SUPER_ACCESS_USER: SUPER_ACCESS_USER,
1415
+ TASKDEFINITION_READ: TASKDEFINITION_READ,
1416
+ TASKDEFINITION_WRITE: TASKDEFINITION_WRITE,
1417
+ THUMBNAIL_READ: THUMBNAIL_READ,
1418
+ THUMBNAIL_WRITE: THUMBNAIL_WRITE,
1419
+ TRANSCODER: TRANSCODER,
1420
+ TRANSFER_READ: TRANSFER_READ,
1421
+ TRANSFER_WRITE: TRANSFER_WRITE,
1422
+ USER: USER,
1423
+ VXA: VXA,
1424
+ VXA_READ: VXA_READ
1425
+ });
1372
1426
 
1373
- var gcd = function gcd(a, b) {
1374
- return b ? gcd(b, a % b) : a;
1375
- };
1427
+ var _excluded$2 = ["groupName"],
1428
+ _excluded2$1 = ["start", "end"];
1376
1429
 
1377
- var parseAspectRatio = function parseAspectRatio(_ref) {
1378
- var width = _ref.width,
1379
- height = _ref.height;
1380
- var denominator = gcd(width, height);
1381
- var widthRatio = width / denominator;
1382
- var heightRatio = height / denominator;
1430
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1383
1431
 
1384
- if (widthRatio > 21) {
1385
- heightRatio = 1;
1386
- widthRatio = (width / height).toFixed(2);
1387
- }
1432
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1388
1433
 
1389
- return [widthRatio, heightRatio].join(':');
1390
- };
1434
+ var parseValueList$1 = function parseValueList(value) {
1435
+ if (value === undefined) return [];
1436
+ if (value === null) return [{
1437
+ value: ''
1438
+ }];
1391
1439
 
1392
- var parseBaseMediaInfoType = function parseBaseMediaInfoType() {
1393
- var baseMediaInfoType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1440
+ if (Array.isArray(value)) {
1441
+ return value.map(function (valueOrObject) {
1442
+ if (_typeof__default["default"](valueOrObject) === 'object') {
1443
+ return _objectSpread$5({
1444
+ value: valueOrObject.value || ''
1445
+ }, valueOrObject);
1446
+ }
1394
1447
 
1395
- var keyValuePairType = baseMediaInfoType.property,
1396
- props = _objectWithoutProperties(baseMediaInfoType, ["property"]);
1448
+ return {
1449
+ value: valueOrObject
1450
+ };
1451
+ });
1452
+ }
1397
1453
 
1398
- var parsedKeyValuePairType = parseKeyValuePairType(keyValuePairType);
1399
- return _objectSpread2(_objectSpread2({}, parsedKeyValuePairType), props);
1454
+ if (value.value) return [value];
1455
+ return [{
1456
+ value: value
1457
+ }];
1400
1458
  };
1401
1459
 
1402
- var parseFileType = function parseFileType(fileType) {
1403
- var _fileType$uri = fileType.uri,
1404
- uriList = _fileType$uri === void 0 ? [] : _fileType$uri,
1405
- fileSizeBytes = fileType.size,
1406
- hash = fileType.hash,
1407
- path = fileType.path,
1408
- fileId = fileType.id;
1460
+ var parseValue = function parseValue() {
1461
+ var fieldValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1409
1462
 
1410
- var _uriList = _slicedToArray(uriList, 1),
1411
- uri = _uriList[0];
1463
+ if (fieldValue && (fieldValue.value || fieldValue.name)) {
1464
+ var valueList = fieldValue.value,
1465
+ uuid = fieldValue.uuid;
1466
+ var value = parseValueList$1(valueList);
1467
+ return {
1468
+ value: value,
1469
+ uuid: uuid
1470
+ };
1471
+ }
1412
1472
 
1413
- var fileSize = fileSizeBytes !== undefined ? filesize(fileSizeBytes) : '';
1414
- var fileName = path ? path.split('/').pop() : undefined;
1415
1473
  return {
1416
- uri: uri,
1417
- hash: hash,
1418
- fileSize: fileSize,
1419
- fileSizeBytes: fileSizeBytes,
1420
- path: path,
1421
- fileName: fileName,
1422
- fileId: fileId
1474
+ value: parseValueList$1(fieldValue)
1423
1475
  };
1424
1476
  };
1425
1477
 
1426
- var parseContainerComponent = function parseContainerComponent(containerComponent) {
1427
- var _containerComponent$m = containerComponent.mediaInfo,
1428
- mediaInfo = _containerComponent$m === void 0 ? {} : _containerComponent$m,
1429
- _containerComponent$m2 = containerComponent.metadata,
1430
- metadata = _containerComponent$m2 === void 0 ? [] : _containerComponent$m2,
1431
- fileList = containerComponent.file,
1432
- durationTimeCode = containerComponent.duration,
1433
- startTimestamp = containerComponent.startTimestamp,
1434
- startTimecode = containerComponent.startTimecode,
1435
- timeCodeTimeBase = containerComponent.timeCodeTimeBase;
1436
- var containerMetadata = parseKeyValuePairType(metadata);
1437
- var containerMediaInfo = parseBaseMediaInfoType(mediaInfo);
1438
- var containerFormat = containerMediaInfo.Format;
1439
- var videoFormat = containerMediaInfo.Video_Format_List,
1440
- audioFormat = containerMediaInfo.Audio_Format_List,
1441
- textFormat = containerMediaInfo.Text_Format_List;
1442
-
1443
- if (containerFormat === undefined) {
1444
- var format = containerComponent.format;
1445
- containerFormat = format;
1478
+ var parseField$1 = function parseField() {
1479
+ var field = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1480
+ var name = field.name,
1481
+ value = field.value;
1482
+ var parsedValue = parseValue(value);
1483
+ return _objectSpread$5({
1484
+ name: name
1485
+ }, parsedValue);
1486
+ };
1446
1487
 
1447
- if (format && format.includes(',')) {
1448
- var formatList = format.split(',');
1488
+ var shouldBeField = function shouldBeField(_ref) {
1489
+ var name = _ref.name,
1490
+ value = _ref.value;
1491
+ return ['string', 'boolean', 'number'].includes(_typeof__default["default"](value)) || name !== 'group' && Array.isArray(value) || value === null;
1492
+ };
1449
1493
 
1450
- var _formatList = _slicedToArray(formatList, 1);
1494
+ var parseGroup$1 = function parseGroup() {
1495
+ var thisGroup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1496
+ var groupName = thisGroup.name,
1497
+ _thisGroup$value = thisGroup.value,
1498
+ groupsOrFields = _thisGroup$value === void 0 ? {} : _thisGroup$value; // eslint-disable-next-line no-use-before-define
1451
1499
 
1452
- containerFormat = _formatList[0];
1453
- }
1454
- }
1500
+ var _parseGroupsOrFields = parseGroupsOrFields(groupsOrFields),
1501
+ field = _parseGroupsOrFields.field,
1502
+ group = _parseGroupsOrFields.group;
1455
1503
 
1456
- var parsedContainerComponent = {
1457
- containerFormat: containerFormat,
1458
- videoFormat: videoFormat,
1459
- audioFormat: audioFormat,
1460
- textFormat: textFormat,
1461
- containerMetadata: containerMetadata,
1462
- containerMediaInfo: containerMediaInfo
1504
+ return {
1505
+ name: groupName,
1506
+ group: group,
1507
+ field: field
1463
1508
  };
1509
+ };
1464
1510
 
1465
- if (containerMetadata.componentOriginalFilename) {
1466
- parsedContainerComponent.originalFilename = containerMetadata.componentOriginalFilename;
1467
- }
1468
-
1469
- if (durationTimeCode !== undefined && durationTimeCode.samples !== 0) {
1470
- parsedContainerComponent.durationTimeCode = formatTimeCodeType(durationTimeCode);
1471
- parsedContainerComponent.duration = parsedContainerComponent.durationTimeCode.toDuration();
1472
- }
1473
-
1474
- if (startTimestamp) {
1475
- parsedContainerComponent.startTimestamp = formatTimeCodeType(startTimestamp);
1476
- }
1477
-
1478
- if (startTimecode !== undefined && timeCodeTimeBase) {
1479
- parsedContainerComponent.startTimecode = formatTimeCodeType({
1480
- samples: startTimecode,
1481
- timeBase: timeCodeTimeBase
1482
- });
1483
- }
1484
-
1485
- if (fileList) {
1486
- var _fileList = _slicedToArray(fileList, 1),
1487
- fileType = _fileList[0];
1511
+ var parseGroupsOrFields = function parseGroupsOrFields(groupsOrFields) {
1512
+ var group = [];
1513
+ var field = [];
1514
+ Object.entries(groupsOrFields).forEach(function (_ref2) {
1515
+ var _ref3 = _slicedToArray__default["default"](_ref2, 2),
1516
+ name = _ref3[0],
1517
+ value = _ref3[1];
1488
1518
 
1489
- var parsedFileType = parseFileType(fileType);
1490
- parsedContainerComponent = _objectSpread2(_objectSpread2({}, parsedContainerComponent), parsedFileType);
1491
- }
1519
+ if (shouldBeField({
1520
+ name: name,
1521
+ value: value
1522
+ })) {
1523
+ field.push(parseField$1({
1524
+ name: name,
1525
+ value: value
1526
+ }));
1527
+ } else if (Array.isArray(value)) {
1528
+ value.forEach(function (_ref4) {
1529
+ var groupName = _ref4.groupName,
1530
+ groupValue = _objectWithoutProperties__default["default"](_ref4, _excluded$2);
1492
1531
 
1493
- return parsedContainerComponent;
1532
+ group.push(parseGroup$1({
1533
+ name: groupName,
1534
+ value: groupValue
1535
+ }));
1536
+ });
1537
+ } else {
1538
+ group.push(parseGroup$1({
1539
+ name: name,
1540
+ value: value
1541
+ }));
1542
+ }
1543
+ });
1544
+ return {
1545
+ group: group,
1546
+ field: field
1547
+ };
1494
1548
  };
1495
1549
 
1496
- var parseVideoComponent = function parseVideoComponent(videoComponent) {
1497
- var videoCodec = videoComponent.codec,
1498
- bitrate = videoComponent.bitrate,
1499
- fieldOrder = videoComponent.fieldOrder,
1500
- _videoComponent$resol = videoComponent.resolution,
1501
- resolution = _videoComponent$resol === void 0 ? {} : _videoComponent$resol,
1502
- _videoComponent$media = videoComponent.mediaInfo,
1503
- mediaInfo = _videoComponent$media === void 0 ? {} : _videoComponent$media,
1504
- _videoComponent$metad = videoComponent.metadata,
1505
- metadata = _videoComponent$metad === void 0 ? [] : _videoComponent$metad;
1506
- var videoMediaInfo = parseBaseMediaInfoType(mediaInfo);
1507
- var videoMetadata = parseKeyValuePairType(metadata);
1508
- var videoFormat = videoMediaInfo.Format,
1509
- timeBaseText = videoMediaInfo['Frame rate'],
1510
- colorSpace = videoMediaInfo['Color space'],
1511
- colorPrimaries = videoMediaInfo['Color primaries'],
1512
- chromaSubsampling = videoMediaInfo.Colorimetry;
1513
- var timeBase;
1514
- var averageFrameRate = videoComponent.averageFrameRate,
1515
- realBaseFrameRate = videoComponent.realBaseFrameRate;
1516
-
1517
- if (realBaseFrameRate !== undefined) {
1518
- timeBase = {
1519
- numerator: realBaseFrameRate.denominator,
1520
- denominator: realBaseFrameRate.numerator
1521
- };
1522
- } else if (timeBaseText !== undefined) {
1523
- timeBase = formatTimeBaseText(timeBaseText);
1524
- } else if (averageFrameRate !== undefined) {
1525
- timeBase = {
1526
- numerator: averageFrameRate.denominator,
1527
- denominator: averageFrameRate.numerator
1528
- };
1529
- }
1530
-
1531
- var samples = videoMediaInfo['Frame count'];
1532
-
1533
- if (samples === undefined) {
1534
- var numberOfPackets = videoComponent.numberOfPackets;
1535
- if (numberOfPackets !== undefined) samples = numberOfPackets;
1536
- }
1537
-
1538
- var timeCode;
1539
- var frameRate;
1540
- var smpte;
1550
+ var parseTimespan$1 = function parseTimespan() {
1551
+ var timespan = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1541
1552
 
1542
- if (samples && timeBase) {
1543
- timeCode = formatTimeCodeType({
1544
- samples: samples,
1545
- timeBase: timeBase
1546
- });
1547
- frameRate = timeCode.timeBase.toRate(true);
1548
- smpte = timeCode.toSmpte(true);
1549
- }
1553
+ var _ref5 = timespan || {},
1554
+ _ref5$start = _ref5.start,
1555
+ start = _ref5$start === void 0 ? '-INF' : _ref5$start,
1556
+ _ref5$end = _ref5.end,
1557
+ end = _ref5$end === void 0 ? '+INF' : _ref5$end,
1558
+ groupsOrFields = _objectWithoutProperties__default["default"](_ref5, _excluded2$1);
1550
1559
 
1551
- var height = resolution.height,
1552
- width = resolution.width;
1553
- var aspectRatio = parseAspectRatio(resolution);
1554
- var dimension = "".concat(width, "x").concat(height);
1555
- var videoBitrate = bitrate ? filesize(bitrate, {
1556
- bits: true
1557
- }) : undefined;
1558
- return {
1559
- videoFormat: videoFormat,
1560
- dimension: dimension,
1561
- frameRate: frameRate,
1562
- height: height,
1563
- width: width,
1564
- timeBase: timeBase,
1565
- timeCode: timeCode,
1566
- videoCodec: videoCodec,
1567
- smpte: smpte,
1568
- videoBitrate: videoBitrate,
1569
- fieldOrder: fieldOrder,
1570
- colorSpace: colorSpace,
1571
- chromaSubsampling: chromaSubsampling,
1572
- aspectRatio: aspectRatio,
1573
- colorPrimaries: colorPrimaries,
1574
- videoMetadata: videoMetadata,
1575
- videoMediaInfo: videoMediaInfo
1576
- };
1577
- };
1560
+ var _parseGroupsOrFields2 = parseGroupsOrFields(groupsOrFields),
1561
+ group = _parseGroupsOrFields2.group,
1562
+ field = _parseGroupsOrFields2.field;
1578
1563
 
1579
- var parseAudioComponent = function parseAudioComponent(audioComponent) {
1580
- var _audioComponent$timeB = audioComponent.timeBase,
1581
- timeBase = _audioComponent$timeB === void 0 ? {} : _audioComponent$timeB,
1582
- audioChannels = audioComponent.channelCount,
1583
- audioCodec = audioComponent.codec,
1584
- _audioComponent$media = audioComponent.mediaInfo,
1585
- mediaInfo = _audioComponent$media === void 0 ? {} : _audioComponent$media,
1586
- bitrate = audioComponent.bitrate,
1587
- _audioComponent$metad = audioComponent.metadata,
1588
- metadata = _audioComponent$metad === void 0 ? [] : _audioComponent$metad;
1589
- var audioMediaInfo = parseBaseMediaInfoType(mediaInfo);
1590
- var audioMetadata = parseKeyValuePairType(metadata);
1591
- var audioFormat = audioMediaInfo.Format,
1592
- audioBitDepth = audioMediaInfo.Resolution,
1593
- audioBitRateMode = audioMediaInfo.Bit_rate_mode;
1594
- var audioSamplerateSamples = timeBase.denominator ? timeBase.denominator / timeBase.numerator : undefined;
1595
- var audioSamplerate = audioSamplerateSamples ? filesize(audioSamplerateSamples, {
1596
- base: 10,
1597
- round: 1,
1598
- symbols: sampleRateSymbols
1599
- }) : undefined;
1600
- var audioBitrate = bitrate ? filesize(bitrate, {
1601
- base: 10,
1602
- round: 2,
1603
- symbols: bitRateSymbols
1604
- }) : undefined;
1605
1564
  return {
1606
- audioFormat: audioFormat,
1607
- audioCodec: audioCodec,
1608
- audioSamplerate: audioSamplerate,
1609
- audioSamplerateSamples: audioSamplerateSamples,
1610
- audioBitDepth: audioBitDepth,
1611
- audioBitrate: audioBitrate,
1612
- audioBitRateMode: audioBitRateMode,
1613
- audioChannels: audioChannels,
1614
- audioMediaInfo: audioMediaInfo,
1615
- audioMetadata: audioMetadata
1565
+ start: start,
1566
+ end: end,
1567
+ field: field,
1568
+ group: group
1616
1569
  };
1617
1570
  };
1571
+ /**
1572
+ * Create a MetadataType object from a metadata object
1573
+ * @param {Object} metadata={} - object with metadata to create MetadataType object of
1574
+ * @returns {Object} MetadataType
1575
+ */
1618
1576
 
1619
- var parseBinaryComponent = function parseBinaryComponent(binaryComponent) {
1620
- var fileList = binaryComponent.file,
1621
- _binaryComponent$medi = binaryComponent.mediaInfo,
1622
- mediaInfo = _binaryComponent$medi === void 0 ? {} : _binaryComponent$medi,
1623
- _binaryComponent$meta = binaryComponent.metadata,
1624
- metadata = _binaryComponent$meta === void 0 ? [] : _binaryComponent$meta;
1625
- var binaryMetadata = parseKeyValuePairType(metadata);
1626
- var binaryMediaInfo = parseBaseMediaInfoType(mediaInfo);
1627
- var parsedBinaryComponent = {
1628
- binaryMetadata: binaryMetadata,
1629
- binaryMediaInfo: binaryMediaInfo
1630
- };
1631
1577
 
1632
- if (fileList) {
1633
- var _fileList2 = _slicedToArray(fileList, 1),
1634
- fileType = _fileList2[0];
1578
+ var createMetadataType = function createMetadataType() {
1579
+ var metadata = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1580
+ var metadataType = {};
1635
1581
 
1636
- var parsedFileType = parseFileType(fileType);
1637
- parsedBinaryComponent = _objectSpread2(_objectSpread2({}, parsedBinaryComponent), parsedFileType);
1582
+ if (Array.isArray(metadata)) {
1583
+ metadataType.timespan = metadata.map(function (thisTimeSpan) {
1584
+ return parseTimespan$1(thisTimeSpan);
1585
+ });
1586
+ } else {
1587
+ var genericTimespan = parseTimespan$1(metadata);
1588
+ metadataType.timespan = [genericTimespan];
1638
1589
  }
1639
1590
 
1640
- return parsedBinaryComponent;
1591
+ return metadataType;
1641
1592
  };
1642
1593
 
1643
- var parseShapeType = function parseShapeType() {
1644
- var shapeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1645
- var parsedShape = {};
1646
- var containerComponent = shapeType.containerComponent,
1647
- videoComponentList = shapeType.videoComponent,
1648
- audioComponentList = shapeType.audioComponent,
1649
- binaryComponentList = shapeType.binaryComponent,
1650
- _shapeType$mimeType = shapeType.mimeType,
1651
- mimeTypeList = _shapeType$mimeType === void 0 ? [] : _shapeType$mimeType,
1652
- _shapeType$tag = shapeType.tag,
1653
- tagList = _shapeType$tag === void 0 ? [] : _shapeType$tag;
1654
-
1655
- var _tagList = _slicedToArray(tagList, 1);
1594
+ var sortTimespanList = function sortTimespanList(timespan1, timespan2) {
1595
+ var firstStart = timespan1.start;
1596
+ var secondStart = timespan2.start;
1656
1597
 
1657
- parsedShape.tag = _tagList[0];
1598
+ var _firstStart$split = firstStart.split('@'),
1599
+ _firstStart$split2 = _slicedToArray__default["default"](_firstStart$split, 1),
1600
+ first = _firstStart$split2[0];
1658
1601
 
1659
- var _mimeTypeList = _slicedToArray(mimeTypeList, 1);
1602
+ var _secondStart$split = secondStart.split('@'),
1603
+ _secondStart$split2 = _slicedToArray__default["default"](_secondStart$split, 1),
1604
+ second = _secondStart$split2[0];
1660
1605
 
1661
- parsedShape.mimeType = _mimeTypeList[0];
1606
+ if (Number(first) < Number(second)) {
1607
+ return -1;
1608
+ }
1662
1609
 
1663
- if (containerComponent) {
1664
- var parsedContainerComponent = parseContainerComponent(containerComponent);
1665
- parsedShape = _objectSpread2(_objectSpread2({}, parsedShape), parsedContainerComponent);
1610
+ if (Number(first) > Number(second)) {
1611
+ return 1;
1666
1612
  }
1667
1613
 
1668
- if (videoComponentList) {
1669
- var _videoComponentList = _slicedToArray(videoComponentList, 1),
1670
- videoComponent = _videoComponentList[0];
1614
+ return 0;
1615
+ };
1671
1616
 
1672
- var parsedVideoComponent = parseVideoComponent(videoComponent);
1673
- parsedShape = _objectSpread2(_objectSpread2({}, parsedShape), parsedVideoComponent);
1674
- }
1617
+ var _excluded$1 = ["value"],
1618
+ _excluded2 = ["field", "group"],
1619
+ _excluded3 = ["field", "group"];
1675
1620
 
1676
- if (audioComponentList) {
1677
- var _audioComponentList = _slicedToArray(audioComponentList, 1),
1678
- audioComponent = _audioComponentList[0];
1621
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1679
1622
 
1680
- var parsedAudioComponent = parseAudioComponent(audioComponent);
1681
- parsedShape = _objectSpread2(_objectSpread2({}, parsedShape), parsedAudioComponent);
1682
- }
1623
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1683
1624
 
1684
- if (binaryComponentList) {
1685
- var _binaryComponentList = _slicedToArray(binaryComponentList, 1),
1686
- binaryComponent = _binaryComponentList[0];
1625
+ var parseValueList = function parseValueList() {
1626
+ var valueList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1627
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1628
+ var _options$arrayOnSingl = options.arrayOnSingle,
1629
+ arrayOnSingle = _options$arrayOnSingl === void 0 ? true : _options$arrayOnSingl,
1630
+ _options$arrayOnSingl2 = options.arrayOnSingleValue,
1631
+ arrayOnSingleValue = _options$arrayOnSingl2 === void 0 ? true : _options$arrayOnSingl2,
1632
+ joinValue = options.joinValue,
1633
+ includeAttributes = options.includeAttributes,
1634
+ includeValueAttributes = options.includeValueAttributes;
1635
+ if (includeAttributes || includeValueAttributes) return valueList;
1636
+ var valueArray = [];
1637
+ valueList.forEach(function (thisValue) {
1638
+ if (thisValue.value) valueArray.push(thisValue.value);
1639
+ });
1640
+ if (joinValue) return valueArray.join(joinValue);
1687
1641
 
1688
- var parsedBinaryComponent = parseBinaryComponent(binaryComponent);
1689
- parsedShape = _objectSpread2(_objectSpread2({}, parsedShape), parsedBinaryComponent);
1642
+ if (arrayOnSingle === false || arrayOnSingleValue === false && valueArray.length === 1) {
1643
+ return valueArray[0];
1690
1644
  }
1691
1645
 
1692
- return parsedShape;
1646
+ return valueArray;
1693
1647
  };
1694
1648
 
1695
- var parseMediaConvertPreset = function parseMediaConvertPreset(transcodePresetType) {
1696
- var output = {};
1697
- var description = transcodePresetType.description,
1698
- _transcodePresetType$ = transcodePresetType.mediaconvert;
1699
- _transcodePresetType$ = _transcodePresetType$ === void 0 ? {} : _transcodePresetType$;
1700
- var _transcodePresetType$2 = _transcodePresetType$.outputSetting,
1701
- outputSetting = _transcodePresetType$2 === void 0 ? [] : _transcodePresetType$2;
1702
- output.description = description;
1703
- if (outputSetting.length === 0) return output;
1704
- var mc = JSON.parse(outputSetting[0]);
1705
- var _mc$Settings = mc.Settings;
1706
- _mc$Settings = _mc$Settings === void 0 ? {} : _mc$Settings;
1707
- var ContainerSettings = _mc$Settings.ContainerSettings,
1708
- VideoDescription = _mc$Settings.VideoDescription,
1709
- AudioDescriptions = _mc$Settings.AudioDescriptions;
1710
- output.containerFormat = ContainerSettings.Container;
1649
+ var parseField = function parseField() {
1650
+ var field = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1651
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1652
+ var includeAttributes = options.includeAttributes,
1653
+ includeFieldAttributes = options.includeFieldAttributes;
1711
1654
 
1712
- if (ContainerSettings) {
1713
- output.containerFormat = ContainerSettings.Container;
1655
+ var _field$value = field.value,
1656
+ value = _field$value === void 0 ? [] : _field$value,
1657
+ attributes = _objectWithoutProperties__default["default"](field, _excluded$1);
1658
+
1659
+ var parsedValueList = parseValueList(value, options);
1660
+ if (includeAttributes || includeFieldAttributes) return _objectSpread$4(_objectSpread$4({}, attributes), {}, {
1661
+ value: parsedValueList
1662
+ });
1663
+ return parsedValueList;
1664
+ };
1665
+
1666
+ var parseFieldList = function parseFieldList() {
1667
+ var fieldList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1668
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1669
+ var joinValue = options.joinValue,
1670
+ includeAttributes = options.includeAttributes,
1671
+ includeFieldAttributes = options.includeFieldAttributes,
1672
+ includeValueAttributes = options.includeValueAttributes;
1673
+ var output = {};
1674
+ var fieldAsList = options.fieldAsList;
1675
+
1676
+ if (fieldAsList) {
1677
+ return fieldList.map(function (thisField) {
1678
+ return parseField(thisField, options);
1679
+ });
1714
1680
  }
1715
1681
 
1716
- if (VideoDescription) {
1717
- var _VideoDescription$Cod = VideoDescription.CodecSettings,
1718
- CodecSettings = _VideoDescription$Cod === void 0 ? {} : _VideoDescription$Cod;
1682
+ fieldList.forEach(function (thisField) {
1683
+ var key = thisField.name;
1684
+ var parsedField = parseField(thisField, options);
1719
1685
 
1720
- var Codec = CodecSettings.Codec,
1721
- otherSettings = _objectWithoutProperties(CodecSettings, ["Codec"]);
1686
+ if (output[key]) {
1687
+ if (includeAttributes || includeFieldAttributes) {
1688
+ var currentValue = output[key].value;
1689
+ var parsedValue = parsedField.value;
1722
1690
 
1723
- output.videoFormat = Codec;
1724
- var height = VideoDescription.Height,
1725
- width = VideoDescription.Width;
1726
- output.height = height;
1727
- output.width = width;
1691
+ if (joinValue && !includeAttributes && !includeValueAttributes) {
1692
+ output[key].value = [currentValue, parsedValue].join(joinValue);
1693
+ } else {
1694
+ output[key].value = parsedValue.concat(currentValue);
1695
+ }
1696
+ } else {
1697
+ var _currentValue = output[key];
1698
+ var _parsedValue = parsedField;
1728
1699
 
1729
- if (height && width) {
1730
- output.dimension = "".concat(width, "x").concat(height);
1731
- output.aspectRatio = parseAspectRatio({
1732
- height: height,
1733
- width: width
1734
- });
1700
+ if (joinValue) {
1701
+ output[key] = [_currentValue, _parsedValue].join(joinValue);
1702
+ } else {
1703
+ output[key] = _parsedValue.concat(_currentValue);
1704
+ }
1705
+ }
1706
+ } else {
1707
+ output[key] = parsedField;
1735
1708
  }
1709
+ });
1710
+ return output;
1711
+ };
1736
1712
 
1737
- var _Object$values = Object.values(otherSettings),
1738
- _Object$values2 = _slicedToArray(_Object$values, 1),
1739
- codecSpecs = _Object$values2[0];
1713
+ var parseGroup = function parseGroup() {
1714
+ var group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1715
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1716
+ var includeAttributes = options.includeAttributes,
1717
+ includeGroupAttributes = options.includeGroupAttributes,
1718
+ flat = options.flat,
1719
+ flatGroup = options.flatGroup,
1720
+ groupAsList = options.groupAsList,
1721
+ fieldAsList = options.fieldAsList;
1740
1722
 
1741
- if (codecSpecs) {
1742
- output.fieldOrder = codecSpecs.InterlaceMode;
1743
- if (output.fieldOrder && output.fieldOrder.includes('TOP')) output.fieldOrder = 'interlaced';
1744
- output.videoBitrate = codecSpecs.Bitrate;
1745
- var numerator = codecSpecs.FramerateDenominator; // other way round to vs ¯\_(ツ)_/¯
1723
+ var _group$field = group.field,
1724
+ fieldList = _group$field === void 0 ? [] : _group$field,
1725
+ _group$group = group.group,
1726
+ groupList = _group$group === void 0 ? [] : _group$group,
1727
+ attributes = _objectWithoutProperties__default["default"](group, _excluded2);
1746
1728
 
1747
- var denominator = codecSpecs.FramerateNumerator;
1748
- var timeBase = formatTimeBaseType({
1749
- denominator: denominator,
1750
- numerator: numerator
1729
+ var parsedFieldList = parseFieldList(fieldList, options); // eslint-disable-next-line no-use-before-define
1730
+
1731
+ var parsedGroupList = parseGroupList(groupList, options);
1732
+ var output = {};
1733
+
1734
+ if (includeAttributes || includeGroupAttributes) {
1735
+ Object.assign(output, attributes);
1736
+ }
1737
+
1738
+ if (flat || flatGroup) {
1739
+ if (groupAsList) {
1740
+ Object.assign(output, {
1741
+ group: parsedGroupList
1751
1742
  });
1752
- output.timeBase = timeBase;
1753
- output.frameRate = timeBase.toRate(true);
1743
+ } else {
1744
+ Object.assign(output, parsedGroupList);
1745
+ }
1746
+
1747
+ if (fieldAsList) {
1748
+ Object.assign(output, {
1749
+ field: parsedFieldList
1750
+ });
1751
+ } else {
1752
+ Object.assign(output, parsedFieldList);
1754
1753
  }
1754
+ } else {
1755
+ Object.assign(output, {
1756
+ field: parsedFieldList
1757
+ });
1758
+ Object.assign(output, {
1759
+ group: parsedGroupList
1760
+ });
1755
1761
  }
1756
1762
 
1757
- if (AudioDescriptions && AudioDescriptions.length > 0) {
1758
- var _AudioDescriptions$0$ = AudioDescriptions[0].CodecSettings,
1759
- _CodecSettings = _AudioDescriptions$0$ === void 0 ? {} : _AudioDescriptions$0$;
1763
+ return output;
1764
+ };
1760
1765
 
1761
- var _Codec = _CodecSettings.Codec,
1762
- _otherSettings = _objectWithoutProperties(_CodecSettings, ["Codec"]);
1766
+ var parseGroupList = function parseGroupList() {
1767
+ var groupList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1768
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1769
+ var groupAsList = options.groupAsList;
1763
1770
 
1764
- output.audioFormat = _Codec;
1771
+ if (groupAsList) {
1772
+ return groupList.map(function (thisGroup) {
1773
+ return parseGroup(thisGroup, options);
1774
+ });
1775
+ }
1765
1776
 
1766
- var _Object$values3 = Object.values(_otherSettings),
1767
- _Object$values4 = _slicedToArray(_Object$values3, 1),
1768
- _codecSpecs = _Object$values4[0];
1777
+ var output = {};
1778
+ groupList.forEach(function (thisGroup) {
1779
+ var key = thisGroup.name;
1780
+ var parsedGroup = parseGroup(thisGroup, options);
1769
1781
 
1770
- if (_codecSpecs) {
1771
- output.audioSamplerate = _codecSpecs.SampleRate;
1772
- output.audioBitrate = _codecSpecs.Bitrate;
1773
- output.audioBitRateMode = _codecSpecs.RateControlMode;
1782
+ if (output[key]) {
1783
+ var _output$key = output[key],
1784
+ currentField = _output$key.field,
1785
+ currentGroup = _output$key.group;
1786
+ var parsedField = parsedGroup.field,
1787
+ parsedGroupList = parsedGroup.group;
1788
+ output[key].field = _objectSpread$4(_objectSpread$4({}, currentField), parsedField);
1789
+ output[key].group = _objectSpread$4(_objectSpread$4({}, currentGroup), parsedGroupList);
1790
+ } else {
1791
+ output[key] = parsedGroup;
1774
1792
  }
1775
- }
1776
-
1793
+ });
1777
1794
  return output;
1778
1795
  };
1796
+ /**
1797
+ * Parses timespan according to specified options.
1798
+ * The attributes can be targeted for each sub-type.
1799
+ * @param {Object} timespan={} - The timespan response from the API.
1800
+ * @param {Object} options={} - Options which change how the metadataType is parsed.
1801
+ * @param {string} options.joinValue=undefined - String to join the values, eg ','.
1802
+ * @param {boolean} options.includeAttributes=false - Include attributes on all objects.
1803
+ * @param {boolean} options.includeTimespanAttributes=false - Include attributes on timespans.
1804
+ * @param {boolean} options.includeGroupAttributes=false - Include attributes on groups.
1805
+ * @param {boolean} options.includeFieldAttributes=false - Include attributes on fields.
1806
+ * @param {boolean} options.includeValueAttributes=false - Include attributes on values.
1807
+ * @param {boolean} options.flat=false - Flatten to key/value (Note: keys may be overwritten).
1808
+ * @param {boolean} options.flatTimespan=false - Flatten timespan.
1809
+ * @param {boolean} options.flatGroup=false - Flatten group.
1810
+ * @param {boolean} options.groupAsList=false - Return groups as list.
1811
+ * @param {boolean} options.fieldAsList=false - Return fields as list.
1812
+ * @param {boolean} options.arrayOnSingle=true - Return fields as array even if single field.
1813
+ * @param {boolean} options.arrayOnSingleValue=true - Return fields as array even if single field value.
1814
+ * @returns {Object} Metadata object parsed according to options.
1815
+ */
1779
1816
 
1780
- var parseTranscodePreset = function parseTranscodePreset(transcodePresetType) {
1781
- var output = {};
1782
- var description = transcodePresetType.description,
1783
- format = transcodePresetType.format,
1784
- audio = transcodePresetType.audio,
1785
- video = transcodePresetType.video,
1786
- mediaconvert = transcodePresetType.mediaconvert;
1787
- if (mediaconvert) return parseMediaConvertPreset(transcodePresetType);
1788
- output.description = description;
1789
- output.containerFormat = format;
1790
1817
 
1791
- if (video) {
1792
- output.videoFormat = video.codec;
1793
- output.videoBitrate = video.bitrate;
1818
+ var parseTimespan = function parseTimespan() {
1819
+ var timespan = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1820
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1821
+ var includeAttributes = options.includeAttributes,
1822
+ includeTimespanAttributes = options.includeTimespanAttributes,
1823
+ flat = options.flat,
1824
+ flatTimespan = options.flatTimespan,
1825
+ groupAsList = options.groupAsList,
1826
+ fieldAsList = options.fieldAsList;
1794
1827
 
1795
- if (video.framerate) {
1796
- var timeBase = formatTimeBaseType(video.framerate);
1797
- output.timeBase = timeBase;
1798
- output.frameRate = timeBase.toRate(true);
1799
- }
1828
+ var _timespan$field = timespan.field,
1829
+ fieldList = _timespan$field === void 0 ? [] : _timespan$field,
1830
+ _timespan$group = timespan.group,
1831
+ groupList = _timespan$group === void 0 ? [] : _timespan$group,
1832
+ attributes = _objectWithoutProperties__default["default"](timespan, _excluded3);
1800
1833
 
1801
- if (video.scaling) {
1802
- var _video$scaling = video.scaling,
1803
- height = _video$scaling.height,
1804
- width = _video$scaling.width;
1805
- output.height = height;
1806
- output.width = width;
1834
+ var field = parseFieldList(fieldList, options);
1835
+ var group = parseGroupList(groupList, options);
1836
+ var output = {};
1807
1837
 
1808
- if (height && width) {
1809
- output.dimension = "".concat(width, "x").concat(height);
1810
- output.aspectRatio = parseAspectRatio({
1811
- height: height,
1812
- width: width
1813
- });
1814
- }
1815
- }
1838
+ if (includeAttributes || includeTimespanAttributes) {
1839
+ Object.assign(output, attributes);
1816
1840
  }
1817
1841
 
1818
- if (audio) {
1819
- var audioFormat = audio.codec,
1820
- channel = audio.channel;
1821
- output.audioFormat = audioFormat;
1822
- if (channel) output.audioChannels = channel.length;
1842
+ if (flat || flatTimespan) {
1843
+ if (groupAsList) {
1844
+ Object.assign(output, {
1845
+ group: group
1846
+ });
1847
+ } else {
1848
+ Object.assign(output, group);
1849
+ }
1850
+
1851
+ if (fieldAsList) {
1852
+ Object.assign(output, {
1853
+ field: field
1854
+ });
1855
+ } else {
1856
+ Object.assign(output, field);
1857
+ }
1858
+ } else {
1859
+ Object.assign(output, {
1860
+ field: field
1861
+ });
1862
+ Object.assign(output, {
1863
+ group: group
1864
+ });
1823
1865
  }
1824
1866
 
1825
1867
  return output;
1826
1868
  };
1827
1869
 
1828
- var parseFacetType = function parseFacetType() {
1829
- var facetType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1830
- var output = {};
1870
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1831
1871
 
1832
- var facetFieldReducer = function facetFieldReducer(a, _ref) {
1833
- var fieldValue = _ref.fieldValue,
1834
- value = _ref.value;
1835
- return _objectSpread2(_objectSpread2({}, a), {}, _defineProperty({}, fieldValue, value));
1836
- };
1837
-
1838
- facetType.forEach(function (_ref2) {
1839
- var name = _ref2.name,
1840
- field = _ref2.field,
1841
- count = _ref2.count;
1842
- output[name || field] = count.reduce(facetFieldReducer, {});
1843
- });
1844
- return output;
1845
- }; // eslint-disable-next-line import/prefer-default-export
1846
-
1847
- /* Note that VS may calculate +/- unit in another way */
1848
- var parseNowDate = function parseNowDate() {
1849
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'NOW';
1850
-
1851
- if (value.startsWith('NOW')) {
1852
- if (value === 'NOW') return new Date();
1853
- var sign = value[3];
1854
- var number = Number(value.match(/(\d+)/)[0]);
1855
- var unit = value.match(/(\d.*)/)[0].replace(/\d/g, '');
1856
- var nowDiff = new Date(); // eslint-disable-next-line default-case
1857
-
1858
- switch (unit) {
1859
- case 'HOUR':
1860
- case 'HOURS':
1861
- if (sign === '+') nowDiff.setHours(nowDiff.getHours() + number);
1862
- if (sign === '-') nowDiff.setHours(nowDiff.getHours() - number);
1863
- break;
1864
-
1865
- case 'DAY':
1866
- case 'DAYS':
1867
- if (sign === '+') nowDiff.setDate(nowDiff.getDate() + number);
1868
- if (sign === '-') nowDiff.setDate(nowDiff.getDate() - number);
1869
- break;
1870
-
1871
- case 'MONTH':
1872
- case 'MONTHS':
1873
- if (sign === '+') nowDiff.setMonth(nowDiff.getMonth() + number);
1874
- if (sign === '-') nowDiff.setMonth(nowDiff.getMonth() - number);
1875
- break;
1876
-
1877
- case 'YEAR':
1878
- case 'YEARS':
1879
- if (sign === '+') nowDiff.setFullYear(nowDiff.getFullYear() + number);
1880
- if (sign === '-') nowDiff.setFullYear(nowDiff.getFullYear() - number);
1881
- break;
1882
- }
1883
-
1884
- return nowDiff;
1885
- }
1886
-
1887
- return new Date(value);
1888
- };
1872
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1873
+ /**
1874
+ * Parses timespanList according to specified options.
1875
+ * The attributes can be targeted for each sub-type.
1876
+ * @param {Object[]} timespanList - The timespanList response from the API.
1877
+ * @param {Object} options - Options which change how the metadataType is parsed.
1878
+ * @param {string} options.joinValue - String to join the values, eg ','.
1879
+ * @param {boolean} options.includeAttributes - Include attributes on all objects.
1880
+ * @param {boolean} options.includeMetadataAttributes - Include attributes on root.
1881
+ * @param {boolean} options.includeTimespanAttributes - Include attributes on timespans.
1882
+ * @param {boolean} options.includeGroupAttributes - Include attributes on groups.
1883
+ * @param {boolean} options.includeFieldAttributes - Include attributes on fields.
1884
+ * @param {boolean} options.includeValueAttributes - Include attributes on values.
1885
+ * @param {boolean} options.flat - Flatten to key/value (Note: keys may be overwritten).
1886
+ * @param {boolean} options.flatTimespan - Flatten timespan.
1887
+ * @param {boolean} options.flatGroup - Flatten group.
1888
+ * @param {boolean} options.sortTimespan - Sort timespan by start time.
1889
+ * @param {boolean} options.timespanAsList - Return timespans as list.
1890
+ * @param {boolean} options.groupAsList - Return groups as list.
1891
+ * @param {boolean} options.fieldAsList - Return fields as list.
1892
+ * @param {boolean} options.arrayOnSingle=true - Return fields as array even if single field.
1893
+ * @param {boolean} options.arrayOnSingleValue=true - Return fields as array even if single field value.
1894
+ * @returns {Object} Metadata object parsed according to options.
1895
+ */
1889
1896
 
1890
- var createFacetType = function createFacetType() {
1891
- var fieldList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1897
+ var parseTimespanList = function parseTimespanList() {
1898
+ var timespanList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1892
1899
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1893
- return fieldList.map(function (field) {
1894
- return {
1895
- field: field,
1896
- name: field,
1897
- count: options.count || true,
1898
- exclude: fieldList
1899
- };
1900
- });
1901
- }; // eslint-disable-next-line import/prefer-default-export
1902
-
1903
- /* eslint-disable import/prefer-default-export */
1904
- var parseValueList$1 = function parseValueList(value) {
1905
- if (value === undefined) return [];
1906
- if (value === null) return [{
1907
- value: ''
1908
- }];
1909
-
1910
- if (Array.isArray(value)) {
1911
- return value.map(function (valueOrObject) {
1912
- if (_typeof(valueOrObject) === 'object') {
1913
- return _objectSpread2({
1914
- value: valueOrObject.value || ''
1915
- }, valueOrObject);
1916
- }
1900
+ var joinTimespan = options.joinTimespan,
1901
+ flat = options.flat;
1902
+ var timespanAsList = options.timespanAsList;
1917
1903
 
1918
- return {
1919
- value: valueOrObject
1920
- };
1904
+ if (timespanAsList) {
1905
+ return timespanList.map(function (thisTimespan) {
1906
+ return parseTimespan(thisTimespan, options);
1921
1907
  });
1922
1908
  }
1923
1909
 
1924
- if (value.value) return [value];
1925
- return [{
1926
- value: value
1927
- }];
1928
- };
1929
-
1930
- var parseValue = function parseValue() {
1931
- var fieldValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1932
-
1933
- if (fieldValue && (fieldValue.value || fieldValue.name)) {
1934
- var valueList = fieldValue.value,
1935
- uuid = fieldValue.uuid;
1936
- var value = parseValueList$1(valueList);
1937
- return {
1938
- value: value,
1939
- uuid: uuid
1940
- };
1941
- }
1942
-
1943
- return {
1944
- value: parseValueList$1(fieldValue)
1945
- };
1946
- };
1947
-
1948
- var parseField$1 = function parseField() {
1949
- var field = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1950
- var name = field.name,
1951
- value = field.value;
1952
- var parsedValue = parseValue(value);
1953
- return _objectSpread2({
1954
- name: name
1955
- }, parsedValue);
1956
- };
1957
-
1958
- var shouldBeField = function shouldBeField(_ref) {
1959
- var name = _ref.name,
1960
- value = _ref.value;
1961
- return ['string', 'boolean', 'number'].includes(_typeof(value)) || name !== 'group' && Array.isArray(value) || value === null;
1962
- };
1963
-
1964
- var parseGroup$1 = function parseGroup() {
1965
- var thisGroup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1966
- var groupName = thisGroup.name,
1967
- _thisGroup$value = thisGroup.value,
1968
- groupsOrFields = _thisGroup$value === void 0 ? {} : _thisGroup$value; // eslint-disable-next-line no-use-before-define
1969
-
1970
- var _parseGroupsOrFields = parseGroupsOrFields(groupsOrFields),
1971
- field = _parseGroupsOrFields.field,
1972
- group = _parseGroupsOrFields.group;
1973
-
1974
- return {
1975
- name: groupName,
1976
- group: group,
1977
- field: field
1978
- };
1979
- };
1980
-
1981
- var parseGroupsOrFields = function parseGroupsOrFields(groupsOrFields) {
1982
- var group = [];
1983
- var field = [];
1984
- Object.entries(groupsOrFields).forEach(function (_ref2) {
1985
- var _ref3 = _slicedToArray(_ref2, 2),
1986
- name = _ref3[0],
1987
- value = _ref3[1];
1988
-
1989
- if (shouldBeField({
1990
- name: name,
1991
- value: value
1992
- })) {
1993
- field.push(parseField$1({
1994
- name: name,
1995
- value: value
1996
- }));
1997
- } else if (Array.isArray(value)) {
1998
- value.forEach(function (_ref4) {
1999
- var groupName = _ref4.groupName,
2000
- groupValue = _objectWithoutProperties(_ref4, ["groupName"]);
1910
+ var output = {};
1911
+ timespanList.forEach(function (thisTimespan) {
1912
+ var start = thisTimespan.start,
1913
+ end = thisTimespan.end;
1914
+ var key = [start, end].join(joinTimespan || '_');
1915
+ var parsedTimespan = parseTimespan(thisTimespan, options);
2001
1916
 
2002
- // eslint-disable-next-line no-use-before-define
2003
- group.push(parseGroup$1({
2004
- name: groupName,
2005
- value: groupValue
2006
- }));
2007
- });
1917
+ if (flat) {
1918
+ output = _objectSpread$3(_objectSpread$3({}, output), parsedTimespan);
1919
+ } else if (output[key]) {
1920
+ var _output$key = output[key],
1921
+ currentField = _output$key.field,
1922
+ currentGroup = _output$key.group;
1923
+ var parsedField = parsedTimespan.field,
1924
+ parsedGroup = parsedTimespan.group;
1925
+ output[key].field = _objectSpread$3(_objectSpread$3({}, currentField), parsedField);
1926
+ output[key].group = _objectSpread$3(_objectSpread$3({}, currentGroup), parsedGroup);
2008
1927
  } else {
2009
- // eslint-disable-next-line no-use-before-define
2010
- group.push(parseGroup$1({
2011
- name: name,
2012
- value: value
2013
- }));
2014
- }
2015
- });
2016
- return {
2017
- group: group,
2018
- field: field
2019
- };
2020
- };
2021
-
2022
- var parseTimeSpan = function parseTimeSpan(timeSpan) {
2023
- var _timeSpan$start = timeSpan.start,
2024
- start = _timeSpan$start === void 0 ? '-INF' : _timeSpan$start,
2025
- _timeSpan$end = timeSpan.end,
2026
- end = _timeSpan$end === void 0 ? '+INF' : _timeSpan$end,
2027
- groupsOrFields = _objectWithoutProperties(timeSpan, ["start", "end"]);
2028
-
2029
- var _parseGroupsOrFields2 = parseGroupsOrFields(groupsOrFields),
2030
- group = _parseGroupsOrFields2.group,
2031
- field = _parseGroupsOrFields2.field;
2032
-
2033
- return {
2034
- start: start,
2035
- end: end,
2036
- field: field,
2037
- group: group
2038
- };
2039
- };
2040
-
2041
- var createMetadataType = function createMetadataType() {
2042
- var metadataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2043
- var newMetadataType = {};
2044
-
2045
- if (Array.isArray(metadataType)) {
2046
- newMetadataType.timespan = metadataType.map(function (thisTimeSpan) {
2047
- return parseTimeSpan(thisTimeSpan);
2048
- });
2049
- } else {
2050
- var genericTimespan = parseTimeSpan(metadataType);
2051
- newMetadataType.timespan = [genericTimespan];
2052
- }
2053
-
2054
- return newMetadataType;
2055
- };
2056
-
2057
- function timeToCueTime(_ref) {
2058
- var _ref$hours = _ref.hours,
2059
- hours = _ref$hours === void 0 ? 0 : _ref$hours,
2060
- _ref$minutes = _ref.minutes,
2061
- minutes = _ref$minutes === void 0 ? 0 : _ref$minutes,
2062
- _ref$seconds = _ref.seconds,
2063
- seconds = _ref$seconds === void 0 ? 0 : _ref$seconds,
2064
- _ref$partialSeconds = _ref.partialSeconds,
2065
- partialSeconds = _ref$partialSeconds === void 0 ? 0 : _ref$partialSeconds;
2066
- var hourStr = hours.toFixed().padStart(2, '0');
2067
- var minStr = minutes.toFixed().padStart(2, '0');
2068
- var secondsStr = seconds.toFixed().padStart(2, '0');
2069
- var partialStr = (partialSeconds * 10).toFixed().padStart(3, '0');
2070
- return "".concat(hourStr, ":").concat(minStr, ":").concat(secondsStr, ".").concat(partialStr);
2071
- }
2072
-
2073
- function metadataTypeToWebVtt(_ref2) {
2074
- var metadataType = _ref2.metadataType,
2075
- _ref2$subtitleGroup = _ref2.subtitleGroup,
2076
- subtitleGroup = _ref2$subtitleGroup === void 0 ? 'stl_subtitle' : _ref2$subtitleGroup,
2077
- _ref2$subtitleField = _ref2.subtitleField,
2078
- subtitleField = _ref2$subtitleField === void 0 ? 'stl_text' : _ref2$subtitleField;
2079
- var parseOptions = {
2080
- includeTimespanAttributes: true,
2081
- flatTimespan: true,
2082
- flatGroup: true,
2083
- joinValue: ','
2084
- };
2085
-
2086
- var _ref3 = metadataType || {},
2087
- _ref3$timespan = _ref3.timespan,
2088
- timespanList = _ref3$timespan === void 0 ? [] : _ref3$timespan;
2089
-
2090
- if (timespanList.length === 0) return '';
2091
- var sortedTimespans = timespanList.sort(sortTimespanList);
2092
- var parsedTimespans = sortedTimespans.map(function (timespanType) {
2093
- return parseTimespan(timespanType, parseOptions);
2094
- });
2095
- var vttCues = parsedTimespans.map(function (thisTimespan) {
2096
- var startText = thisTimespan.start,
2097
- endText = thisTimespan.end,
2098
- _thisTimespan$subtitl = thisTimespan[subtitleGroup];
2099
- _thisTimespan$subtitl = _thisTimespan$subtitl === void 0 ? {} : _thisTimespan$subtitl;
2100
- var text = _thisTimespan$subtitl[subtitleField];
2101
- if (!text) return '';
2102
- var startTime = formatTimeCodeText(startText).toTime();
2103
- var start = timeToCueTime(startTime);
2104
- var endTime = formatTimeCodeText(endText).toTime();
2105
- var end = timeToCueTime(endTime);
2106
- return "".concat(start, " --> ").concat(end, " line:0%\r").concat(text, "\r");
2107
- });
2108
- return "WEBVTT\n\n\n".concat(vttCues.join('\n'));
2109
- }
2110
-
2111
- var IMAGE_MIME_TYPES = ['image/apng', 'image/bmp', 'image/gif', 'image/jpeg', 'image/x-icon', 'image/png', 'image/svg+xml'];
2112
- var VIDEO_MIME_TYPES = ['video/mp4'];
2113
- var AUDIO_MIME_TYPES = ['audio/mp4', 'audio/mpeg', 'audio/x-aac', 'audio/aac', 'audio/x-wav', 'audio/wav', 'audio/accp', 'audio/ogg', 'audio/webm', 'audio/x-flac'];
2114
- var DEFAULT_ALLOWED_MIME_TYPES = [].concat(VIDEO_MIME_TYPES, IMAGE_MIME_TYPES, AUDIO_MIME_TYPES);
2115
- var DEFAULT_ALLOWED_METHODS = ['http', 'https'];
2116
- var MP4_MIMETYPE = 'video/mp4';
2117
- var QUICKTIME_MIMETYPE = 'video/quicktime';
2118
- var M4V_MIMETYPE = 'video/x-m4v';
2119
- var MP4_CONTAINER = 'MPEG-4';
2120
- var MOV_CONTAINER = 'mov';
2121
- var H264_CODEC = 'h264'; // Sort by tags in the order of previewShapeOrder, secondary alphabetical.
2122
- // using reverse() so the first has highest index
2123
-
2124
- var PREVIEW_SHAPE_ORDER = ['__mp4', '__mp3_160k', '__png', '__jpeg', '__gif', 'original'].reverse();
2125
-
2126
- var defaultSortPriority = function defaultSortPriority(_ref, _ref2) {
2127
- var firstEl = _ref.shape.tag;
2128
- var secondEl = _ref2.shape.tag;
2129
-
2130
- if (PREVIEW_SHAPE_ORDER.includes(firstEl) || PREVIEW_SHAPE_ORDER.includes(secondEl)) {
2131
- return PREVIEW_SHAPE_ORDER.indexOf(secondEl) - PREVIEW_SHAPE_ORDER.indexOf(firstEl);
2132
- }
2133
-
2134
- return firstEl.toLowerCase().localeCompare(secondEl.toLowerCase());
2135
- };
2136
-
2137
- var filterShapeSource = function filterShapeSource() {
2138
- var itemType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2139
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2140
- var _options$allowedMimeT = options.allowedMimeTypes,
2141
- allowedMimeTypes = _options$allowedMimeT === void 0 ? DEFAULT_ALLOWED_MIME_TYPES : _options$allowedMimeT,
2142
- _options$sortPriority = options.sortPriority,
2143
- sortPriority = _options$sortPriority === void 0 ? defaultSortPriority : _options$sortPriority,
2144
- _options$allowedMetho = options.allowedMethods,
2145
- allowedMethods = _options$allowedMetho === void 0 ? DEFAULT_ALLOWED_METHODS : _options$allowedMetho,
2146
- _options$sourceKey = options.sourceKey,
2147
- sourceKey = _options$sourceKey === void 0 ? 'src' : _options$sourceKey,
2148
- _options$mimeTypeKey = options.mimeTypeKey,
2149
- mimeTypeKey = _options$mimeTypeKey === void 0 ? 'type' : _options$mimeTypeKey,
2150
- _options$shapeKey = options.shapeKey,
2151
- shapeKey = _options$shapeKey === void 0 ? 'shape' : _options$shapeKey;
2152
- var _itemType$shape = itemType.shape,
2153
- shapeList = _itemType$shape === void 0 ? [] : _itemType$shape;
2154
- var parsedShapeList = shapeList.reduce(function (acc, shapeType) {
2155
- var type;
2156
- var src;
2157
- var shape = parseShapeType(shapeType);
2158
- var uri = shape.uri,
2159
- mimeType = shape.mimeType,
2160
- containerFormat = shape.containerFormat,
2161
- videoCodec = shape.videoCodec;
2162
-
2163
- if (mimeType) {
2164
- type = mimeType;
2165
- if ((mimeType === QUICKTIME_MIMETYPE || mimeType === M4V_MIMETYPE) && (containerFormat === MP4_CONTAINER || containerFormat === MOV_CONTAINER) && videoCodec === H264_CODEC) type = MP4_MIMETYPE;
2166
- }
2167
-
2168
- if (uri) {
2169
- if (allowedMethods) {
2170
- var _uri$split = uri.split('://'),
2171
- _uri$split2 = _slicedToArray(_uri$split, 1),
2172
- thisMethod = _uri$split2[0];
2173
-
2174
- if (allowedMethods.includes(thisMethod)) src = uri;
2175
- } else {
2176
- src = uri;
2177
- }
2178
- }
2179
-
2180
- if (src && allowedMimeTypes.includes(type)) {
2181
- var _acc$push;
2182
-
2183
- acc.push((_acc$push = {}, _defineProperty(_acc$push, sourceKey, src), _defineProperty(_acc$push, mimeTypeKey, type), _defineProperty(_acc$push, shapeKey, shape), _acc$push));
2184
- }
2185
-
2186
- return acc;
2187
- }, []);
2188
- if (typeof sortPriority === 'function') parsedShapeList.sort(defaultSortPriority);
2189
- return parsedShapeList;
2190
- };
2191
-
2192
- var IMAGE = 'IMAGE';
2193
- var AUDIO = 'AUDIO';
2194
- var VIDEO = 'VIDEO';
2195
- var DOCUMENT = 'DOCUMENT';
2196
-
2197
- var getShapeMediaType = function getShapeMediaType() {
2198
- var shape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2199
- var mimeType = shape.mimeType,
2200
- videoCodec = shape.videoCodec,
2201
- audioCodec = shape.audioCodec;
2202
- if (!mimeType) return undefined;
2203
-
2204
- if (mimeType.startsWith('audio/')) {
2205
- if (audioCodec !== undefined) return AUDIO;
2206
- }
2207
-
2208
- if (mimeType.startsWith('video/')) {
2209
- if (videoCodec !== undefined) return VIDEO;
2210
- if (audioCodec !== undefined) return AUDIO;
2211
- }
2212
-
2213
- if (mimeType.startsWith('image/')) return IMAGE;
2214
- if (mimeType.endsWith('/pdf')) return DOCUMENT;
2215
- if (mimeType.startsWith('text/')) return DOCUMENT;
2216
- if (mimeType.endsWith('/msword')) return DOCUMENT;
2217
- if (mimeType.endsWith('/json')) return DOCUMENT;
2218
- if (mimeType.endsWith('/xml')) return DOCUMENT;
2219
- return undefined;
2220
- };
2221
-
2222
- var findNearestThumbnail = function findNearestThumbnail() {
2223
- var itemType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2224
- var timeCodeText = arguments.length > 1 ? arguments[1] : undefined;
2225
- var tcSeconds = formatTimeCodeText(timeCodeText).toSeconds();
2226
- var _itemType$thumbnails = itemType.thumbnails,
2227
- thumbnails = _itemType$thumbnails === void 0 ? {} : _itemType$thumbnails;
2228
- var _thumbnails$uri = thumbnails.uri,
2229
- srcList = _thumbnails$uri === void 0 ? [] : _thumbnails$uri;
2230
- var srcTcSeconds = srcList.map(function (url) {
2231
- var tc = new URL(url).pathname.split('/').pop();
2232
- return formatTimeCodeText(tc).toSeconds();
2233
- });
2234
- var nearestSrcIndex = srcTcSeconds.reduce(function (nearestIndex, curr, currIndex) {
2235
- return Math.abs(curr - tcSeconds) < Math.abs(srcTcSeconds[nearestIndex] - tcSeconds) ? currIndex : nearestIndex;
2236
- }, 0);
2237
- return srcList[nearestSrcIndex];
2238
- };
2239
-
2240
- var ACCESSCONTROL_READ = '_accesscontrol_read';
2241
- var ACCESSCONTROL_WRITE = '_accesscontrol_write';
2242
- var ADMINISTRATOR = '_administrator';
2243
- var AUTO_PROJECTION_READ = '_auto_projection_read';
2244
- var AUTO_PROJECTION_WRITE = '_auto_projection_write';
2245
- var COLLECTION_NOTIFICATION_READ = '_collection_notification_read';
2246
- var COLLECTION_NOTIFICATION_WRITE = '_collection_notification_write';
2247
- var COLLECTION_READ = '_collection_read';
2248
- var COLLECTION_WRITE = '_collection_write';
2249
- var DELETION_LOCK_NOTIFICATION_READ = '_deletion_lock_notification_read';
2250
- var DELETION_LOCK_NOTIFICATION_WRITE = '_deletion_lock_notification_write';
2251
- var DELETION_LOCK_READ = '_deletion_lock_read';
2252
- var DELETION_LOCK_WRITE = '_deletion_lock_write';
2253
- var DOCUMENT_NOTIFICATION_READ = '_document_notification_read';
2254
- var DOCUMENT_NOTIFICATION_WRITE = '_document_notification_write';
2255
- var DOCUMENT_READ = '_document_read';
2256
- var DOCUMENT_WRITE = '_document_write';
2257
- var ERROR_READ = '_error_read';
2258
- var ERROR_WRITE = '_error_write';
2259
- var EXPORT = '_export';
2260
- var EXPORT_TEMPLATE_READ = '_export_template_read';
2261
- var EXPORT_TEMPLATE_WRITE = '_export_template_write';
2262
- var EXTERNAL_ID_READ = '_external_id_read';
2263
- var EXTERNAL_ID_WRITE = '_external_id_write';
2264
- var FILE_NOTIFICATION_READ = '_file_notification_read';
2265
- var FILE_NOTIFICATION_WRITE = '_file_notification_write';
2266
- var FILE_READ = '_file_read';
2267
- var FILE_WRITE = '_file_write';
2268
- var GROUP_READ = '_group_read';
2269
- var GROUP_WRITE = '_group_write';
2270
- var IMPORT_WRITE = '_import';
2271
- var ITEM_ID_READ = '_item_id_read';
2272
- var ITEM_ID_WRITE = '_item_id_write';
2273
- var ITEM_NOTIFICATION_READ = '_item_notification_read';
2274
- var ITEM_NOTIFICATION_WRITE = '_item_notification_write';
2275
- var ITEM_WRITE = '_item_write';
2276
- var ITEM_SEARCH = '_item_search';
2277
- var ITEM_SHAPE_READ = '_item_shape_read';
2278
- var ITEM_SHAPE_WRITE = '_item_shape_write';
2279
- var ITEM_TIMELINE_READ = '_item_timeline_read';
2280
- var ITEM_TIMELINE_WRITE = '_item_timeline_write';
2281
- var ITEM_URI = '_item_uri';
2282
- var JOB_NOTIFICATION_READ = '_job_notification_read';
2283
- var JOB_NOTIFICATION_WRITE = '_job_notification_write';
2284
- var JOB_READ = '_job_read';
2285
- var JOB_WRITE = '_job_write';
2286
- var LIBRARY_READ = '_library_read';
2287
- var LIBRARY_WRITE = '_library_write';
2288
- var LOCK_READ = '_lock_read';
2289
- var LOCK_WRITE = '_lock_write';
2290
- var LOG_READ = '_log_read';
2291
- var METADATA_DATASET_READ = '_metadata_dataset_read';
2292
- var METADATA_DATASET_WRITE = '_metadata_dataset_write';
2293
- var METADATA_FIELD_GROUP_READ = '_metadata_field_group_read';
2294
- var METADATA_FIELD_GROUP_WRITE = '_metadata_field_group_write';
2295
- var METADATA_FIELD_READ = '_metadata_field_read';
2296
- var METADATA_FIELD_WRITE = '_metadata_field_write';
2297
- var METADATA_GLOBAL_READ = '_metadata_global_read';
2298
- var METADATA_GLOBAL_WRITE = '_metadata_global_write';
2299
- var METADATA_LOCK_READ = '_metadata_lock_read';
2300
- var METADATA_LOCK_WRITE = '_metadata_lock_write';
2301
- var METADATA_READ = '_metadata_read';
2302
- var METADATA_SCHEMA_READ = '_metadata_schema_read';
2303
- var METADATA_SCHEMA_WRITE = '_metadata_schema_write';
2304
- var METADATA_WRITE = '_metadata_write';
2305
- var OTIF_ANALYZE = '_otif_analyze';
2306
- var OTIF_READ = '_otif_read';
2307
- var OTIF_WRITE = '_otif_write';
2308
- var PLACEHOLDER_NOTIFICATION_READ = '_placeholder_notification_read';
2309
- var PLACEHOLDER_NOTIFICATION_WRITE = '_placeholder_notification_write';
2310
- var PROJECTION_READ = '_projection_read';
2311
- var PROJECTION_WRITE = '_projection_write';
2312
- var QUOTA_NOTIFICATION_READ = '_quota_notification_read';
2313
- var QUOTA_NOTIFICATION_WRITE = '_quota_notification_write';
2314
- var QUOTA_READ = '_quota_read';
2315
- var QUOTA_WRITE = '_quota_write';
2316
- var RELATION_READ = '_relation_read';
2317
- var RELATION_WRITE = '_relation_write';
2318
- var RESOURCE_READ = '_resource_read';
2319
- var RESOURCE_WRITE = '_resource_write';
2320
- var RUN_AS = '_run_as';
2321
- var SEARCH = '_search';
2322
- var SEQUENCE_READ = '_sequence_read';
2323
- var SEQUENCE_WRITE = '_sequence_write';
2324
- var SHAPE_TAG_READ = '_shape_tag_read';
2325
- var SHAPE_TAG_WRITE = '_shape_tag_write';
2326
- var SITE_MANAGER = '_site_manager';
2327
- var SITE_RULE_READ = '_site_rule_read';
2328
- var SITE_RULE_WRITE = '_site_rule_write';
2329
- var STORAGE_GROUP_READ = '_storage_group_read';
2330
- var STORAGE_GROUP_WRITE = '_storage_group_write';
2331
- var STORAGE_NOTIFICATION_READ = '_storage_notification_read';
2332
- var STORAGE_NOTIFICATION_WRITE = '_storage_notification_write';
2333
- var STORAGE_READ = '_storage_read';
2334
- var STORAGE_RULE_READ = '_storage_rule_read';
2335
- var STORAGE_RULE_WRITE = '_storage_rule_write';
2336
- var STORAGE_WRITE = '_storage_write';
2337
- var SUPER_ACCESS_USER = '_super_access_user';
2338
- var TASKDEFINITION_READ = '_taskdefinition_read';
2339
- var TASKDEFINITION_WRITE = '_taskdefinition_write';
2340
- var THUMBNAIL_READ = '_thumbnail_read';
2341
- var THUMBNAIL_WRITE = '_thumbnail_write';
2342
- var TRANSCODER = '_transcoder';
2343
- var TRANSFER_READ = '_transfer_read';
2344
- var TRANSFER_WRITE = '_transfer_write';
2345
- var USER = '_user';
2346
- var VXA = '_vxa';
2347
- var VXA_READ = '_vxa_read';
2348
-
2349
- var roles = /*#__PURE__*/Object.freeze({
2350
- __proto__: null,
2351
- ACCESSCONTROL_READ: ACCESSCONTROL_READ,
2352
- ACCESSCONTROL_WRITE: ACCESSCONTROL_WRITE,
2353
- ADMINISTRATOR: ADMINISTRATOR,
2354
- AUTO_PROJECTION_READ: AUTO_PROJECTION_READ,
2355
- AUTO_PROJECTION_WRITE: AUTO_PROJECTION_WRITE,
2356
- COLLECTION_NOTIFICATION_READ: COLLECTION_NOTIFICATION_READ,
2357
- COLLECTION_NOTIFICATION_WRITE: COLLECTION_NOTIFICATION_WRITE,
2358
- COLLECTION_READ: COLLECTION_READ,
2359
- COLLECTION_WRITE: COLLECTION_WRITE,
2360
- DELETION_LOCK_NOTIFICATION_READ: DELETION_LOCK_NOTIFICATION_READ,
2361
- DELETION_LOCK_NOTIFICATION_WRITE: DELETION_LOCK_NOTIFICATION_WRITE,
2362
- DELETION_LOCK_READ: DELETION_LOCK_READ,
2363
- DELETION_LOCK_WRITE: DELETION_LOCK_WRITE,
2364
- DOCUMENT_NOTIFICATION_READ: DOCUMENT_NOTIFICATION_READ,
2365
- DOCUMENT_NOTIFICATION_WRITE: DOCUMENT_NOTIFICATION_WRITE,
2366
- DOCUMENT_READ: DOCUMENT_READ,
2367
- DOCUMENT_WRITE: DOCUMENT_WRITE,
2368
- ERROR_READ: ERROR_READ,
2369
- ERROR_WRITE: ERROR_WRITE,
2370
- EXPORT: EXPORT,
2371
- EXPORT_TEMPLATE_READ: EXPORT_TEMPLATE_READ,
2372
- EXPORT_TEMPLATE_WRITE: EXPORT_TEMPLATE_WRITE,
2373
- EXTERNAL_ID_READ: EXTERNAL_ID_READ,
2374
- EXTERNAL_ID_WRITE: EXTERNAL_ID_WRITE,
2375
- FILE_NOTIFICATION_READ: FILE_NOTIFICATION_READ,
2376
- FILE_NOTIFICATION_WRITE: FILE_NOTIFICATION_WRITE,
2377
- FILE_READ: FILE_READ,
2378
- FILE_WRITE: FILE_WRITE,
2379
- GROUP_READ: GROUP_READ,
2380
- GROUP_WRITE: GROUP_WRITE,
2381
- IMPORT_WRITE: IMPORT_WRITE,
2382
- ITEM_ID_READ: ITEM_ID_READ,
2383
- ITEM_ID_WRITE: ITEM_ID_WRITE,
2384
- ITEM_NOTIFICATION_READ: ITEM_NOTIFICATION_READ,
2385
- ITEM_NOTIFICATION_WRITE: ITEM_NOTIFICATION_WRITE,
2386
- ITEM_WRITE: ITEM_WRITE,
2387
- ITEM_SEARCH: ITEM_SEARCH,
2388
- ITEM_SHAPE_READ: ITEM_SHAPE_READ,
2389
- ITEM_SHAPE_WRITE: ITEM_SHAPE_WRITE,
2390
- ITEM_TIMELINE_READ: ITEM_TIMELINE_READ,
2391
- ITEM_TIMELINE_WRITE: ITEM_TIMELINE_WRITE,
2392
- ITEM_URI: ITEM_URI,
2393
- JOB_NOTIFICATION_READ: JOB_NOTIFICATION_READ,
2394
- JOB_NOTIFICATION_WRITE: JOB_NOTIFICATION_WRITE,
2395
- JOB_READ: JOB_READ,
2396
- JOB_WRITE: JOB_WRITE,
2397
- LIBRARY_READ: LIBRARY_READ,
2398
- LIBRARY_WRITE: LIBRARY_WRITE,
2399
- LOCK_READ: LOCK_READ,
2400
- LOCK_WRITE: LOCK_WRITE,
2401
- LOG_READ: LOG_READ,
2402
- METADATA_DATASET_READ: METADATA_DATASET_READ,
2403
- METADATA_DATASET_WRITE: METADATA_DATASET_WRITE,
2404
- METADATA_FIELD_GROUP_READ: METADATA_FIELD_GROUP_READ,
2405
- METADATA_FIELD_GROUP_WRITE: METADATA_FIELD_GROUP_WRITE,
2406
- METADATA_FIELD_READ: METADATA_FIELD_READ,
2407
- METADATA_FIELD_WRITE: METADATA_FIELD_WRITE,
2408
- METADATA_GLOBAL_READ: METADATA_GLOBAL_READ,
2409
- METADATA_GLOBAL_WRITE: METADATA_GLOBAL_WRITE,
2410
- METADATA_LOCK_READ: METADATA_LOCK_READ,
2411
- METADATA_LOCK_WRITE: METADATA_LOCK_WRITE,
2412
- METADATA_READ: METADATA_READ,
2413
- METADATA_SCHEMA_READ: METADATA_SCHEMA_READ,
2414
- METADATA_SCHEMA_WRITE: METADATA_SCHEMA_WRITE,
2415
- METADATA_WRITE: METADATA_WRITE,
2416
- OTIF_ANALYZE: OTIF_ANALYZE,
2417
- OTIF_READ: OTIF_READ,
2418
- OTIF_WRITE: OTIF_WRITE,
2419
- PLACEHOLDER_NOTIFICATION_READ: PLACEHOLDER_NOTIFICATION_READ,
2420
- PLACEHOLDER_NOTIFICATION_WRITE: PLACEHOLDER_NOTIFICATION_WRITE,
2421
- PROJECTION_READ: PROJECTION_READ,
2422
- PROJECTION_WRITE: PROJECTION_WRITE,
2423
- QUOTA_NOTIFICATION_READ: QUOTA_NOTIFICATION_READ,
2424
- QUOTA_NOTIFICATION_WRITE: QUOTA_NOTIFICATION_WRITE,
2425
- QUOTA_READ: QUOTA_READ,
2426
- QUOTA_WRITE: QUOTA_WRITE,
2427
- RELATION_READ: RELATION_READ,
2428
- RELATION_WRITE: RELATION_WRITE,
2429
- RESOURCE_READ: RESOURCE_READ,
2430
- RESOURCE_WRITE: RESOURCE_WRITE,
2431
- RUN_AS: RUN_AS,
2432
- SEARCH: SEARCH,
2433
- SEQUENCE_READ: SEQUENCE_READ,
2434
- SEQUENCE_WRITE: SEQUENCE_WRITE,
2435
- SHAPE_TAG_READ: SHAPE_TAG_READ,
2436
- SHAPE_TAG_WRITE: SHAPE_TAG_WRITE,
2437
- SITE_MANAGER: SITE_MANAGER,
2438
- SITE_RULE_READ: SITE_RULE_READ,
2439
- SITE_RULE_WRITE: SITE_RULE_WRITE,
2440
- STORAGE_GROUP_READ: STORAGE_GROUP_READ,
2441
- STORAGE_GROUP_WRITE: STORAGE_GROUP_WRITE,
2442
- STORAGE_NOTIFICATION_READ: STORAGE_NOTIFICATION_READ,
2443
- STORAGE_NOTIFICATION_WRITE: STORAGE_NOTIFICATION_WRITE,
2444
- STORAGE_READ: STORAGE_READ,
2445
- STORAGE_RULE_READ: STORAGE_RULE_READ,
2446
- STORAGE_RULE_WRITE: STORAGE_RULE_WRITE,
2447
- STORAGE_WRITE: STORAGE_WRITE,
2448
- SUPER_ACCESS_USER: SUPER_ACCESS_USER,
2449
- TASKDEFINITION_READ: TASKDEFINITION_READ,
2450
- TASKDEFINITION_WRITE: TASKDEFINITION_WRITE,
2451
- THUMBNAIL_READ: THUMBNAIL_READ,
2452
- THUMBNAIL_WRITE: THUMBNAIL_WRITE,
2453
- TRANSCODER: TRANSCODER,
2454
- TRANSFER_READ: TRANSFER_READ,
2455
- TRANSFER_WRITE: TRANSFER_WRITE,
2456
- USER: USER,
2457
- VXA: VXA,
2458
- VXA_READ: VXA_READ
2459
- });
1928
+ output[key] = parsedTimespan;
1929
+ }
1930
+ });
1931
+ return output;
1932
+ };
1933
+
1934
+ var _excluded = ["timespan"];
1935
+ /**
1936
+ * Parses MetadataType according to specified options.
1937
+ * The attributes can be targeted for each sub-type.
1938
+ * @param {Object} metadataType - The MetadataType response from the API.
1939
+ * @param {Object} options - Options which change how the metadataType is parsed.
1940
+ * @param {string} options.joinValue - String to join the values, eg ','.
1941
+ * @param {boolean} options.includeAttributes - Include attributes on all objects.
1942
+ * @param {boolean} options.includeMetadataAttributes - Include attributes on root.
1943
+ * @param {boolean} options.includeTimespanAttributes - Include attributes on timespans.
1944
+ * @param {boolean} options.includeGroupAttributes - Include attributes on groups.
1945
+ * @param {boolean} options.includeFieldAttributes - Include attributes on fields.
1946
+ * @param {boolean} options.includeValueAttributes - Include attributes on values.
1947
+ * @param {boolean} options.flat - Flatten to key/value (Note: keys may be overwritten).
1948
+ * @param {boolean} options.flatTimespan - Flatten timespan.
1949
+ * @param {boolean} options.flatGroup - Flatten group.
1950
+ * @param {boolean} options.sortTimespan - Sort timespan by start time.
1951
+ * @param {boolean} options.timespanAsList - Return timespans as list.
1952
+ * @param {boolean} options.groupAsList - Return groups as list.
1953
+ * @param {boolean} options.fieldAsList - Return fields as list.
1954
+ * @param {boolean} options.arrayOnSingle=true - Return fields as array even if single field.
1955
+ * @param {boolean} options.arrayOnSingleValue=true - Return fields as array even if single field value.
1956
+ * @returns {Object} Metadata object parsed according to options.
1957
+ */
1958
+
1959
+ var parseMetadataType = function parseMetadataType() {
1960
+ var metadataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1961
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1962
+ var includeAttributes = options.includeAttributes,
1963
+ includeMetadataAttributes = options.includeMetadataAttributes,
1964
+ sortTimespan = options.sortTimespan;
1965
+
1966
+ var _metadataType$timespa = metadataType.timespan,
1967
+ timespanList = _metadataType$timespa === void 0 ? [] : _metadataType$timespa,
1968
+ attributes = _objectWithoutProperties__default["default"](metadataType, _excluded);
1969
+
1970
+ if (sortTimespan) timespanList.sort(sortTimespanList);
1971
+ var timespan = parseTimespanList(timespanList, options);
1972
+
1973
+ if (includeAttributes || includeMetadataAttributes) {
1974
+ Object.assign(timespan, attributes);
1975
+ }
1976
+
1977
+ return timespan;
1978
+ };
2460
1979
 
2461
1980
  var parseSimpleMetadataType = function parseSimpleMetadataType() {
2462
1981
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
@@ -2466,6 +1985,19 @@ var parseSimpleMetadataType = function parseSimpleMetadataType() {
2466
1985
  return parseKeyValuePairType(field);
2467
1986
  };
2468
1987
 
1988
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1989
+
1990
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1991
+
1992
+ /**
1993
+ * Parses highlight timespan responses from the api into key/value object.
1994
+ * The attributes can be targeted for each sub-type.
1995
+ * @param {Object[]} highlightTimespan - A timespan object from the api response.
1996
+ * @param {Object} options - Options which change how the timespans are parsed.
1997
+ * @param {boolean} options.arrayOnSingle=true - Return an array if there is a single value.
1998
+ * @param {boolean} options.timespanAsList=false - Return timespans as list.
1999
+ * @param {string} options.joinValue - String to join the values, eg ','.
2000
+ */
2469
2001
  var parseHighlightTimespan = function parseHighlightTimespan() {
2470
2002
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2471
2003
  _ref$field = _ref.field,
@@ -2492,29 +2024,32 @@ var parseHighlightTimespan = function parseHighlightTimespan() {
2492
2024
  var fieldValue;
2493
2025
 
2494
2026
  if (arrayOnSingle === false && valueList.length === 1) {
2495
- var _valueList = _slicedToArray(valueList, 1);
2027
+ var _valueList = _slicedToArray__default["default"](valueList, 1);
2496
2028
 
2497
2029
  fieldValue = _valueList[0];
2498
2030
  } else if (joinValue) fieldValue = valueList.join(joinValue);else fieldValue = valueList;
2499
2031
 
2500
- return _objectSpread2(_objectSpread2({}, a), {}, _defineProperty({}, name, fieldValue));
2032
+ return _objectSpread$2(_objectSpread$2({}, a), {}, _defineProperty__default["default"]({}, name, fieldValue));
2501
2033
  }, initialValue);
2502
2034
  return fieldList;
2503
2035
  };
2036
+
2037
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2038
+
2039
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2504
2040
  /**
2505
- * Parses Highlight Timespans into key/value object.
2041
+ * Parses highlight timespans responses from the api into key/value object.
2506
2042
  * The attributes can be targeted for each sub-type.
2507
- * @param {Object} highlightTimespanList - A list of timespans.
2043
+ * @param {Object} highlightTimespanList - A list of timespans from the api response.
2508
2044
  * @param {Object} options - Options which change how the timespans are parsed.
2509
- * @param {Object} options.arrayOnSingle - Return an array if there is a single value.
2510
- * @param {Object} options.joinValue - String to join the values, eg ','.
2511
- * @param {Object} options.flat - Flatten to field-name/field-value (Note: field-values may be overwritten).
2512
- * @param {Object} options.flatTimespan - Flatten timespan to object with start/end as key.
2513
- * @param {Object} options.timespanAsList - Return timespans as list.
2514
- * @param {Object} options.joinTimespan - String character to join the start/end timecodes.
2045
+ * @param {boolean} options.arrayOnSingle=true - Return an array if there is a single value.
2046
+ * @param {string} options.joinValue - String to join the values, eg ','.
2047
+ * @param {boolean} options.timespanAsList=false - Return timespans as list.
2048
+ * @param {boolean} options.flat=false - Flatten to field-name/field-value (Note: field-values may be overwritten).
2049
+ * @param {boolean} options.flatTimespan=false - Flatten timespan to object with start/end as key.
2050
+ * @param {string} options.joinTimespan=_ - Character to join the start/end timecodes.
2515
2051
  */
2516
2052
 
2517
-
2518
2053
  var parseHighlightTimespanList = function parseHighlightTimespanList() {
2519
2054
  var highlightTimespanList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2520
2055
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -2527,38 +2062,247 @@ var parseHighlightTimespanList = function parseHighlightTimespanList() {
2527
2062
  return parseHighlightTimespan(timespan, opts);
2528
2063
  });
2529
2064
  if (flat === true || flatTimespan === true) return highlightTimespanList.reduce(function (a, timespan) {
2530
- return _objectSpread2(_objectSpread2({}, a), parseHighlightTimespan(timespan, opts));
2065
+ return _objectSpread$1(_objectSpread$1({}, a), parseHighlightTimespan(timespan, opts));
2531
2066
  }, {});
2532
2067
  return highlightTimespanList.reduce(function (a, timespan) {
2533
- return _objectSpread2(_objectSpread2({}, a), {}, _defineProperty({}, [timespan.start, timespan.end].join(joinTimespan), parseHighlightTimespan(timespan, opts)));
2068
+ return _objectSpread$1(_objectSpread$1({}, a), {}, _defineProperty__default["default"]({}, [timespan.start, timespan.end].join(joinTimespan), parseHighlightTimespan(timespan, opts)));
2534
2069
  }, {});
2535
2070
  };
2536
2071
 
2537
- var PDF = 'PDF';
2538
- var TEXT = 'TEXT';
2539
- var MSWORD = 'MSWORD';
2540
- var JSON$1 = 'JSON';
2541
- var XML = 'XML';
2072
+ function timeToCueTime(_ref) {
2073
+ var _ref$hours = _ref.hours,
2074
+ hours = _ref$hours === void 0 ? 0 : _ref$hours,
2075
+ _ref$minutes = _ref.minutes,
2076
+ minutes = _ref$minutes === void 0 ? 0 : _ref$minutes,
2077
+ _ref$seconds = _ref.seconds,
2078
+ seconds = _ref$seconds === void 0 ? 0 : _ref$seconds,
2079
+ _ref$partialSeconds = _ref.partialSeconds,
2080
+ partialSeconds = _ref$partialSeconds === void 0 ? 0 : _ref$partialSeconds;
2081
+ var hourStr = hours.toFixed().padStart(2, '0');
2082
+ var minStr = minutes.toFixed().padStart(2, '0');
2083
+ var secondsStr = seconds.toFixed().padStart(2, '0');
2084
+ var partialStr = (partialSeconds * 10).toFixed().padStart(3, '0');
2085
+ return "".concat(hourStr, ":").concat(minStr, ":").concat(secondsStr, ".").concat(partialStr);
2086
+ }
2087
+ /**
2088
+ * Convert subtitle groups to WebVtt subtitle format
2089
+ * @param {Object} input={}
2090
+ * @param {Object} input.metadataType - MetadataType response from API.
2091
+ * @param {string} input.subtitleGroup=stl_subtitle - Name of group containing subtitle field/text.
2092
+ * @param {string} input.subtitleField=stl_text - Name of field (text) to use for the subtitles.
2093
+ * @returns {string} WebVtt subtitles
2094
+ */
2542
2095
 
2543
- var getDocumentType = function getDocumentType() {
2544
- var shape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2545
- var mimeType = shape.mimeType;
2096
+
2097
+ function metadataTypeToWebVtt(_ref2) {
2098
+ var metadataType = _ref2.metadataType,
2099
+ _ref2$subtitleGroup = _ref2.subtitleGroup,
2100
+ subtitleGroup = _ref2$subtitleGroup === void 0 ? 'stl_subtitle' : _ref2$subtitleGroup,
2101
+ _ref2$subtitleField = _ref2.subtitleField,
2102
+ subtitleField = _ref2$subtitleField === void 0 ? 'stl_text' : _ref2$subtitleField;
2103
+ var parseOptions = {
2104
+ includeTimespanAttributes: true,
2105
+ flatTimespan: true,
2106
+ flatGroup: true,
2107
+ joinValue: ','
2108
+ };
2109
+
2110
+ var _ref3 = metadataType || {},
2111
+ _ref3$timespan = _ref3.timespan,
2112
+ timespanList = _ref3$timespan === void 0 ? [] : _ref3$timespan;
2113
+
2114
+ if (timespanList.length === 0) return '';
2115
+ var sortedTimespans = timespanList.sort(sortTimespanList);
2116
+ var parsedTimespans = sortedTimespans.map(function (timespanType) {
2117
+ return parseTimespan(timespanType, parseOptions);
2118
+ });
2119
+ var vttCues = parsedTimespans.map(function (thisTimespan) {
2120
+ var startText = thisTimespan.start,
2121
+ endText = thisTimespan.end,
2122
+ _thisTimespan$subtitl = thisTimespan[subtitleGroup];
2123
+ _thisTimespan$subtitl = _thisTimespan$subtitl === void 0 ? {} : _thisTimespan$subtitl;
2124
+ var text = _thisTimespan$subtitl[subtitleField];
2125
+ if (!text) return '';
2126
+ var startTime = formatTimeCodeText(startText).toTime();
2127
+ var start = timeToCueTime(startTime);
2128
+ var endTime = formatTimeCodeText(endText).toTime();
2129
+ var end = timeToCueTime(endTime);
2130
+ return "".concat(start, " --> ").concat(end, " line:0%\r").concat(text, "\r");
2131
+ });
2132
+ return "WEBVTT\n\n\n".concat(vttCues.join('\n'));
2133
+ }
2134
+
2135
+ var createFacetType = function createFacetType() {
2136
+ var fieldList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2137
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2138
+ return fieldList.map(function (field) {
2139
+ return {
2140
+ field: field,
2141
+ name: field,
2142
+ count: options.count || true,
2143
+ exclude: fieldList
2144
+ };
2145
+ });
2146
+ };
2147
+
2148
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2149
+
2150
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2151
+
2152
+ var parseFacetType = function parseFacetType() {
2153
+ var facetType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2154
+ var output = {};
2155
+
2156
+ var facetFieldReducer = function facetFieldReducer(a, _ref) {
2157
+ var fieldValue = _ref.fieldValue,
2158
+ value = _ref.value;
2159
+ return _objectSpread(_objectSpread({}, a), {}, _defineProperty__default["default"]({}, fieldValue, value));
2160
+ };
2161
+
2162
+ facetType.forEach(function (_ref2) {
2163
+ var name = _ref2.name,
2164
+ field = _ref2.field,
2165
+ count = _ref2.count;
2166
+ output[name || field] = count.reduce(facetFieldReducer, {});
2167
+ });
2168
+ return output;
2169
+ };
2170
+
2171
+ var IMAGE_MIME_TYPES = ['image/apng', 'image/bmp', 'image/gif', 'image/jpeg', 'image/x-icon', 'image/png', 'image/svg+xml'];
2172
+ var VIDEO_MIME_TYPES = ['video/mp4'];
2173
+ var AUDIO_MIME_TYPES = ['audio/mp4', 'audio/mpeg', 'audio/x-aac', 'audio/aac', 'audio/x-wav', 'audio/wav', 'audio/accp', 'audio/ogg', 'audio/webm', 'audio/x-flac'];
2174
+ var DEFAULT_ALLOWED_MIME_TYPES = [].concat(VIDEO_MIME_TYPES, IMAGE_MIME_TYPES, AUDIO_MIME_TYPES);
2175
+ var DEFAULT_ALLOWED_METHODS = ['http', 'https'];
2176
+ var MP4_MIMETYPE = 'video/mp4';
2177
+ var QUICKTIME_MIMETYPE = 'video/quicktime';
2178
+ var M4V_MIMETYPE = 'video/x-m4v';
2179
+ var MP4_CONTAINER = 'MPEG-4';
2180
+ var MOV_CONTAINER = 'mov';
2181
+ var H264_CODEC = 'h264'; // Sort by tags in the order of previewShapeOrder, secondary alphabetical.
2182
+ // using reverse() so the first has highest index
2183
+
2184
+ var PREVIEW_SHAPE_ORDER = ['__mp4', '__mp3_160k', '__png', '__jpeg', '__gif', 'original'].reverse();
2185
+
2186
+ var defaultSortPriority = function defaultSortPriority(_ref, _ref2) {
2187
+ var firstEl = _ref.shape.tag;
2188
+ var secondEl = _ref2.shape.tag;
2189
+
2190
+ if (PREVIEW_SHAPE_ORDER.includes(firstEl) || PREVIEW_SHAPE_ORDER.includes(secondEl)) {
2191
+ return PREVIEW_SHAPE_ORDER.indexOf(secondEl) - PREVIEW_SHAPE_ORDER.indexOf(firstEl);
2192
+ }
2193
+
2194
+ return firstEl.toLowerCase().localeCompare(secondEl.toLowerCase());
2195
+ };
2196
+
2197
+ var filterShapeSource = function filterShapeSource() {
2198
+ var itemType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2199
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2200
+ var _options$allowedMimeT = options.allowedMimeTypes,
2201
+ allowedMimeTypes = _options$allowedMimeT === void 0 ? DEFAULT_ALLOWED_MIME_TYPES : _options$allowedMimeT,
2202
+ _options$sortPriority = options.sortPriority,
2203
+ sortPriority = _options$sortPriority === void 0 ? defaultSortPriority : _options$sortPriority,
2204
+ _options$allowedMetho = options.allowedMethods,
2205
+ allowedMethods = _options$allowedMetho === void 0 ? DEFAULT_ALLOWED_METHODS : _options$allowedMetho,
2206
+ _options$sourceKey = options.sourceKey,
2207
+ sourceKey = _options$sourceKey === void 0 ? 'src' : _options$sourceKey,
2208
+ _options$mimeTypeKey = options.mimeTypeKey,
2209
+ mimeTypeKey = _options$mimeTypeKey === void 0 ? 'type' : _options$mimeTypeKey,
2210
+ _options$shapeKey = options.shapeKey,
2211
+ shapeKey = _options$shapeKey === void 0 ? 'shape' : _options$shapeKey;
2212
+ var _itemType$shape = itemType.shape,
2213
+ shapeList = _itemType$shape === void 0 ? [] : _itemType$shape;
2214
+ var parsedShapeList = shapeList.reduce(function (acc, shapeType) {
2215
+ var type;
2216
+ var src;
2217
+ var shape = parseShapeType(shapeType);
2218
+ var uri = shape.uri,
2219
+ mimeType = shape.mimeType,
2220
+ containerFormat = shape.containerFormat,
2221
+ videoCodec = shape.videoCodec;
2222
+
2223
+ if (mimeType) {
2224
+ type = mimeType;
2225
+ if ((mimeType === QUICKTIME_MIMETYPE || mimeType === M4V_MIMETYPE) && (containerFormat === MP4_CONTAINER || containerFormat === MOV_CONTAINER) && videoCodec === H264_CODEC) type = MP4_MIMETYPE;
2226
+ }
2227
+
2228
+ if (uri) {
2229
+ if (allowedMethods) {
2230
+ var _uri$split = uri.split('://'),
2231
+ _uri$split2 = _slicedToArray__default["default"](_uri$split, 1),
2232
+ thisMethod = _uri$split2[0];
2233
+
2234
+ if (allowedMethods.includes(thisMethod)) src = uri;
2235
+ } else {
2236
+ src = uri;
2237
+ }
2238
+ }
2239
+
2240
+ if (src && allowedMimeTypes.includes(type)) {
2241
+ var _acc$push;
2242
+
2243
+ acc.push((_acc$push = {}, _defineProperty__default["default"](_acc$push, sourceKey, src), _defineProperty__default["default"](_acc$push, mimeTypeKey, type), _defineProperty__default["default"](_acc$push, shapeKey, shape), _acc$push));
2244
+ }
2245
+
2246
+ return acc;
2247
+ }, []);
2248
+ if (typeof sortPriority === 'function') parsedShapeList.sort(defaultSortPriority);
2249
+ return parsedShapeList;
2250
+ };
2251
+
2252
+ var IMAGE = 'IMAGE';
2253
+ var AUDIO = 'AUDIO';
2254
+ var VIDEO = 'VIDEO';
2255
+ var DOCUMENT = 'DOCUMENT';
2256
+ var getShapeMediaType = function getShapeMediaType() {
2257
+ var shapeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2258
+ var mimeType = shapeType.mimeType,
2259
+ videoCodec = shapeType.videoCodec,
2260
+ audioCodec = shapeType.audioCodec;
2546
2261
  if (!mimeType) return undefined;
2547
- if (mimeType.endsWith('/pdf')) return PDF;
2548
- if (mimeType.startsWith('text/')) return TEXT;
2549
- if (mimeType.endsWith('/msword')) return MSWORD;
2550
- if (mimeType.endsWith('/json')) return JSON$1;
2551
- if (mimeType.endsWith('/xml')) return XML;
2262
+
2263
+ if (mimeType.startsWith('audio/')) {
2264
+ if (audioCodec !== undefined) return AUDIO;
2265
+ }
2266
+
2267
+ if (mimeType.startsWith('video/')) {
2268
+ if (videoCodec !== undefined) return VIDEO;
2269
+ if (audioCodec !== undefined) return AUDIO;
2270
+ }
2271
+
2272
+ if (mimeType.startsWith('image/')) return IMAGE;
2273
+ if (mimeType.endsWith('/pdf')) return DOCUMENT;
2274
+ if (mimeType.startsWith('text/')) return DOCUMENT;
2275
+ if (mimeType.endsWith('/msword')) return DOCUMENT;
2276
+ if (mimeType.endsWith('/json')) return DOCUMENT;
2277
+ if (mimeType.endsWith('/xml')) return DOCUMENT;
2552
2278
  return undefined;
2553
2279
  };
2554
2280
 
2281
+ var findNearestThumbnail = function findNearestThumbnail(itemType, timeCodeText) {
2282
+ var tcSeconds = formatTimeCodeText(timeCodeText).toSeconds();
2283
+
2284
+ var _ref = itemType || {},
2285
+ _ref$thumbnails = _ref.thumbnails,
2286
+ thumbnails = _ref$thumbnails === void 0 ? {} : _ref$thumbnails;
2287
+
2288
+ var _thumbnails$uri = thumbnails.uri,
2289
+ srcList = _thumbnails$uri === void 0 ? [] : _thumbnails$uri;
2290
+ var srcTcSeconds = srcList.map(function (url) {
2291
+ var tc = new URL(url).pathname.split('/').pop();
2292
+ return formatTimeCodeText(tc).toSeconds();
2293
+ });
2294
+ var nearestSrcIndex = srcTcSeconds.reduce(function (nearestIndex, curr, currIndex) {
2295
+ return Math.abs(curr - tcSeconds) < Math.abs(srcTcSeconds[nearestIndex] - tcSeconds) ? currIndex : nearestIndex;
2296
+ }, 0);
2297
+ return srcList[nearestSrcIndex];
2298
+ };
2299
+
2555
2300
  exports.TimeBase = TimeBase;
2556
2301
  exports.TimeCode = TimeCode;
2557
2302
  exports.createFacetType = createFacetType;
2558
2303
  exports.createMetadataType = createMetadataType;
2559
2304
  exports.filterShapeSource = filterShapeSource;
2560
2305
  exports.findNearestThumbnail = findNearestThumbnail;
2561
- exports.findTimespan = findTimespan;
2562
2306
  exports.formatSeconds = formatSeconds;
2563
2307
  exports.formatSecondsPrecise = formatSecondsPrecise;
2564
2308
  exports.formatSmpte = formatSmpte;
@@ -2590,5 +2334,4 @@ exports.parseTimespanList = parseTimespanList;
2590
2334
  exports.parseTranscodePreset = parseTranscodePreset;
2591
2335
  exports.parseVideoComponent = parseVideoComponent;
2592
2336
  exports.roles = roles;
2593
- exports.sortTimespanList = sortTimespanList;
2594
2337
  //# sourceMappingURL=index.js.map