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