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

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