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