@vidispine/vdt-js 22.1.0-pre.3 → 22.2.0-pre.2

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