@eluvio/elv-client-js 4.2.24 → 4.2.27
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/package.json +5 -1
- package/src/client/ABRPublishing.js +33 -19
- package/src/client/Files.js +14 -13
- package/src/client/LiveConf.js +46 -27
- package/src/client/LiveStream.js +15 -5
- package/utilities/MediaIngest.js +424 -0
- package/utilities/README_INGEST.md +332 -0
- package/utilities/lib/abr_profiles/abr_profile_4k_all.json +181 -0
- package/utilities/lib/concerns/Client.js +71 -10
- package/utilities/lib/concerns/CloudAccess.js +2 -2
- package/utilities/lib/concerns/CloudFile.js +14 -7
- package/utilities/lib/data/network_specs.json +13 -0
- package/utilities/lib/models/CredentialSet.js +26 -7
- package/utilities/tests/unit/lib/concerns/Client.test.js +96 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// Create or update a playable media object from specified file(s)
|
|
2
|
+
const R = require("ramda");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
const {ModOpt, NewOpt} = require("./lib/options");
|
|
6
|
+
const Utility = require("./lib/Utility");
|
|
7
|
+
|
|
8
|
+
const ABR = require("@eluvio/elv-abr-profile");
|
|
9
|
+
|
|
10
|
+
const Client = require("./lib/concerns/Client");
|
|
11
|
+
const CloudFile = require("./lib/concerns/CloudFile");
|
|
12
|
+
const Finalize = require("./lib/concerns/Finalize");
|
|
13
|
+
const LocalFile = require("./lib/concerns/LocalFile");
|
|
14
|
+
const LRO = require("./lib/concerns/LRO");
|
|
15
|
+
const ArgLibraryId = require("./lib/concerns/ArgLibraryId");
|
|
16
|
+
const ArgTenant = require("./lib/concerns/ArgTenant");
|
|
17
|
+
const {seconds} = require("./lib/helpers");
|
|
18
|
+
|
|
19
|
+
const AbrProfile = require("./lib/abr_profiles/abr_profile_4k_all.json");
|
|
20
|
+
const STATUS_FILE = "./ingest-status.json";
|
|
21
|
+
|
|
22
|
+
// Status object - used for reporting and resume.
|
|
23
|
+
const status = {
|
|
24
|
+
state: "",
|
|
25
|
+
object_id: "",
|
|
26
|
+
write_token: "",
|
|
27
|
+
master_created: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const SetStatus = statusUpdate => {
|
|
31
|
+
Object.assign(status, statusUpdate);
|
|
32
|
+
fs.writeFileSync(STATUS_FILE, `${JSON.stringify(status, null, 2)}\n`);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
class MediaIngest extends Utility {
|
|
36
|
+
blueprint() {
|
|
37
|
+
return {
|
|
38
|
+
concerns: [Client, CloudFile, Finalize, LocalFile, ArgLibraryId, ArgTenant, LRO],
|
|
39
|
+
options: [
|
|
40
|
+
ModOpt("libraryId", {demand: false, forX: "new media object"}),
|
|
41
|
+
NewOpt("objectId", {
|
|
42
|
+
demand: false,
|
|
43
|
+
descTemplate: "Existing media object to ingest into",
|
|
44
|
+
type: "string"
|
|
45
|
+
}),
|
|
46
|
+
NewOpt("title", {
|
|
47
|
+
demand: false,
|
|
48
|
+
descTemplate: "Title for new media object (required unless --object-id is given)",
|
|
49
|
+
type: "string"
|
|
50
|
+
}),
|
|
51
|
+
NewOpt("drm", {
|
|
52
|
+
default: false,
|
|
53
|
+
descTemplate: "Use DRM for playback",
|
|
54
|
+
type: "boolean"
|
|
55
|
+
}),
|
|
56
|
+
NewOpt("hdrInfoFile", {
|
|
57
|
+
descTemplate: "Path to HDR info JSON file to enable HDR10 ingest. File format: { \"master_display\": \"G(...)B(...)R(...)WP(...)L(...)\", \"max_cll\": \"...,...\" }",
|
|
58
|
+
type: "string"
|
|
59
|
+
}),
|
|
60
|
+
NewOpt("finalize", {
|
|
61
|
+
default: true,
|
|
62
|
+
descTemplate: "Finalize the content object write token after ingest. Use --no-finalize to leave the draft open.",
|
|
63
|
+
type: "boolean"
|
|
64
|
+
}),
|
|
65
|
+
NewOpt("offeringKey", {
|
|
66
|
+
default: "default",
|
|
67
|
+
descTemplate: "Offering key (default: 'default')",
|
|
68
|
+
type: "string"
|
|
69
|
+
}),
|
|
70
|
+
NewOpt("variantKey", {
|
|
71
|
+
default: "default",
|
|
72
|
+
descTemplate: "Master variant key (default: 'default')",
|
|
73
|
+
type: "string"
|
|
74
|
+
}),
|
|
75
|
+
ModOpt("files", {forX: "for new media object"})
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async body() {
|
|
81
|
+
const logger = this.logger;
|
|
82
|
+
|
|
83
|
+
const s3Reference = Boolean(this.args.s3Reference);
|
|
84
|
+
const useS3 = Boolean(this.args.s3Copy || s3Reference);
|
|
85
|
+
const access = useS3
|
|
86
|
+
? this.concerns.CloudFile.credentialSet()
|
|
87
|
+
: undefined;
|
|
88
|
+
|
|
89
|
+
let fileHandles = [];
|
|
90
|
+
const fileInfo = useS3
|
|
91
|
+
? this.concerns.CloudFile.fileInfo()
|
|
92
|
+
: this.concerns.LocalFile.fileInfo(fileHandles);
|
|
93
|
+
const fileConcern = useS3
|
|
94
|
+
? this.concerns.CloudFile
|
|
95
|
+
: this.concerns.LocalFile;
|
|
96
|
+
|
|
97
|
+
// delay getting elvClient until this point so script exits faster
|
|
98
|
+
// if there is a validation error above
|
|
99
|
+
const client = await this.concerns.Client.get();
|
|
100
|
+
|
|
101
|
+
// get type from Tenant
|
|
102
|
+
const tenantInfo = await this.concerns.ArgTenant.tenantInfo();
|
|
103
|
+
|
|
104
|
+
const type = tenantInfo.typeTitle;
|
|
105
|
+
|
|
106
|
+
if(R.isNil(type)) throw Error("Library does not specify content type for media ingests");
|
|
107
|
+
|
|
108
|
+
let {drm, finalize, hdrInfoFile, libraryId, objectId, offeringKey, title, variantKey} = this.args;
|
|
109
|
+
const noFinalize = !finalize;
|
|
110
|
+
const copy = !s3Reference;
|
|
111
|
+
const encrypt = !s3Reference;
|
|
112
|
+
|
|
113
|
+
let id;
|
|
114
|
+
let nodeUrl;
|
|
115
|
+
let writeToken;
|
|
116
|
+
if(status.write_token) {
|
|
117
|
+
id = status.object_id;
|
|
118
|
+
writeToken = status.write_token;
|
|
119
|
+
if(!libraryId) {
|
|
120
|
+
libraryId = await client.ContentObjectLibraryId({objectId: id});
|
|
121
|
+
}
|
|
122
|
+
// Re-pin client to the node holding the draft
|
|
123
|
+
nodeUrl = await client.WriteTokenNodeUrlNetwork({writeToken});
|
|
124
|
+
await client.SetNodes({fabricURIs: [nodeUrl]});
|
|
125
|
+
logger.log(`Resuming from write token ${writeToken} on ${nodeUrl}`);
|
|
126
|
+
} else {
|
|
127
|
+
if(!libraryId && !objectId) {
|
|
128
|
+
throw Error("One of library-id or object-id must be specified");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if(!objectId && !title) {
|
|
132
|
+
throw Error("--title is required when creating a new media object");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if(objectId) {
|
|
136
|
+
if(!libraryId) {
|
|
137
|
+
libraryId = await client.ContentObjectLibraryId({objectId});
|
|
138
|
+
}
|
|
139
|
+
const editResp = await client.EditContentObject({
|
|
140
|
+
libraryId,
|
|
141
|
+
objectId,
|
|
142
|
+
options: type ? { type } : {}
|
|
143
|
+
});
|
|
144
|
+
id = objectId;
|
|
145
|
+
writeToken = editResp.writeToken;
|
|
146
|
+
nodeUrl = editResp.nodeUrl;
|
|
147
|
+
} else {
|
|
148
|
+
const createResp = await client.CreateContentObject({
|
|
149
|
+
libraryId,
|
|
150
|
+
options: type ? { type } : {}
|
|
151
|
+
});
|
|
152
|
+
id = createResp.id;
|
|
153
|
+
writeToken = createResp.writeToken;
|
|
154
|
+
nodeUrl = createResp.nodeUrl;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
await client.authClient.GenerateAuthorizationToken({
|
|
158
|
+
libraryId,
|
|
159
|
+
objectId: id,
|
|
160
|
+
update: true
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
status.object_id = id;
|
|
164
|
+
status.write_token = writeToken;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
SetStatus({state: "object_created"});
|
|
168
|
+
|
|
169
|
+
if(!nodeUrl) {
|
|
170
|
+
nodeUrl = client.WriteTokenNodeUrlLocal({writeToken});
|
|
171
|
+
}
|
|
172
|
+
if(!nodeUrl) {
|
|
173
|
+
nodeUrl = await client.WriteTokenNodeUrlNetwork({writeToken});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
logger.data("object_id", id);
|
|
177
|
+
|
|
178
|
+
if(!status.master_created) {
|
|
179
|
+
logger.log("Uploading files...");
|
|
180
|
+
|
|
181
|
+
const createMasterResponse = await client.CreateProductionMaster({
|
|
182
|
+
libraryId,
|
|
183
|
+
type,
|
|
184
|
+
name: title,
|
|
185
|
+
fileInfo,
|
|
186
|
+
encrypt,
|
|
187
|
+
access,
|
|
188
|
+
copy,
|
|
189
|
+
callback: fileConcern.callback,
|
|
190
|
+
writeToken
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Close file handles (if any)
|
|
194
|
+
this.concerns.LocalFile.closeFileHandles(fileHandles);
|
|
195
|
+
|
|
196
|
+
logger.errorsAndWarnings(createMasterResponse);
|
|
197
|
+
|
|
198
|
+
logger.logList(
|
|
199
|
+
"",
|
|
200
|
+
"Production master default variant created:",
|
|
201
|
+
` Object ID: ${id}`,
|
|
202
|
+
` Write token: ${writeToken}`,
|
|
203
|
+
""
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
if(!R.isNil(createMasterResponse.errors) && !R.isEmpty(createMasterResponse.errors)) throw Error(`Error(s) encountered while inspecting uploaded files: ${createMasterResponse.errors.join("\n")}`);
|
|
207
|
+
|
|
208
|
+
status.master_created = true;
|
|
209
|
+
} else {
|
|
210
|
+
this.concerns.LocalFile.closeFileHandles(fileHandles);
|
|
211
|
+
logger.log(`Skipping upload + master creation (resume), write token ${writeToken}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
SetStatus({state: "master_created", master_created: true});
|
|
215
|
+
|
|
216
|
+
// get production master metadata
|
|
217
|
+
const masterMetadata = (await client.ContentObjectMetadata({
|
|
218
|
+
libraryId,
|
|
219
|
+
objectId: id,
|
|
220
|
+
writeToken,
|
|
221
|
+
metadataSubtree: "/production_master"
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
const sources = R.prop("sources", masterMetadata);
|
|
225
|
+
const variant = R.path(["variants", variantKey], masterMetadata);
|
|
226
|
+
if(R.isNil(variant)) throw Error(`Variant '${variantKey}' not found in production master metadata`);
|
|
227
|
+
|
|
228
|
+
// add info on source files and variant to data if --json selected
|
|
229
|
+
if(this.args.json) {
|
|
230
|
+
logger.data("media_files", sources);
|
|
231
|
+
logger.data("variant_key", variantKey);
|
|
232
|
+
logger.data("variant", variant);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// HDR: inject HDR info into first video stream's sources metadata
|
|
236
|
+
let hdrInfo;
|
|
237
|
+
if(hdrInfoFile) {
|
|
238
|
+
hdrInfo = JSON.parse(fs.readFileSync(hdrInfoFile, "utf8"));
|
|
239
|
+
const fileName = Object.keys(sources)[0];
|
|
240
|
+
const streams = sources[fileName].streams;
|
|
241
|
+
const videoStreamIdx = streams.findIndex(s => s.type === "StreamVideo");
|
|
242
|
+
if(videoStreamIdx < 0) throw Error(`No video stream found in /production_master/sources/${fileName}`);
|
|
243
|
+
|
|
244
|
+
streams[videoStreamIdx].hdr = hdrInfo;
|
|
245
|
+
logger.log(`Adding HDR info to /production_master/sources/${fileName}/streams/${videoStreamIdx}/hdr`);
|
|
246
|
+
|
|
247
|
+
await client.ReplaceMetadata({
|
|
248
|
+
libraryId,
|
|
249
|
+
objectId: id,
|
|
250
|
+
writeToken,
|
|
251
|
+
metadataSubtree: "/production_master/sources",
|
|
252
|
+
metadata: sources
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// generate ABR profile
|
|
257
|
+
const genProfileRetVal = ABR.ABRProfileForVariant(sources, variant, AbrProfile);
|
|
258
|
+
if(!genProfileRetVal.ok) throw Error(`Error(s) encountered while generating ABR profile: ${genProfileRetVal.errors.join("\n")}`);
|
|
259
|
+
|
|
260
|
+
// filter DRM/clear as needed
|
|
261
|
+
const filterProfileRetVal = drm ?
|
|
262
|
+
ABR.ProfileExcludeClear(genProfileRetVal.result) :
|
|
263
|
+
ABR.ProfileExcludeDRM(genProfileRetVal.result);
|
|
264
|
+
if(!filterProfileRetVal.ok) throw Error(`Error(s) encountered while setting playout formats: ${filterProfileRetVal.errors.join("\n")}`);
|
|
265
|
+
|
|
266
|
+
// HDR: add HEVC/10-bit segment specs to the profile
|
|
267
|
+
if(hdrInfo) {
|
|
268
|
+
filterProfileRetVal.result.segment_specs = filterProfileRetVal.result.segment_specs || {};
|
|
269
|
+
filterProfileRetVal.result.segment_specs.video = {
|
|
270
|
+
...(filterProfileRetVal.result.segment_specs.video || {}),
|
|
271
|
+
bit_depth: 10,
|
|
272
|
+
encoding: "h265"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// set up mezzanine offering
|
|
277
|
+
logger.log("Setting up media file conversion...");
|
|
278
|
+
const createMezResponse = await client.CreateABRMezzanine({
|
|
279
|
+
name: title,
|
|
280
|
+
libraryId,
|
|
281
|
+
writeToken,
|
|
282
|
+
type,
|
|
283
|
+
masterWriteToken: writeToken,
|
|
284
|
+
variant: variantKey,
|
|
285
|
+
offeringKey,
|
|
286
|
+
abrProfile: filterProfileRetVal.result
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
logger.errorsAndWarnings(createMezResponse);
|
|
290
|
+
const createMezErrors = createMezResponse.errors;
|
|
291
|
+
if(!R.isNil(createMezErrors) && !R.isEmpty(createMezErrors)) throw Error(`Error(s) encountered while setting up media file conversion: ${createMezErrors.join("\n")}`);
|
|
292
|
+
|
|
293
|
+
SetStatus({state: "mez_created", mez_created: true});
|
|
294
|
+
|
|
295
|
+
logger.log("Starting conversion to streaming format...");
|
|
296
|
+
|
|
297
|
+
const startJobsResponse = await client.StartABRMezzanineJobs({
|
|
298
|
+
libraryId,
|
|
299
|
+
objectId: id,
|
|
300
|
+
offeringKey,
|
|
301
|
+
writeToken
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
logger.errorsAndWarnings(startJobsResponse);
|
|
305
|
+
const startJobsErrors = createMezResponse.errors;
|
|
306
|
+
if(!R.isNil(startJobsErrors) && !R.isEmpty(startJobsErrors)) throw Error(`Error(s) encountered while starting file conversion: ${startJobsErrors.join("\n")}`);
|
|
307
|
+
|
|
308
|
+
writeToken = startJobsResponse.writeToken || writeToken;
|
|
309
|
+
nodeUrl = startJobsResponse.nodeUrl || nodeUrl;
|
|
310
|
+
|
|
311
|
+
const lroWriteToken = R.path(["lro_draft", "write_token"], startJobsResponse) || writeToken;
|
|
312
|
+
const lroNode = R.path(["lro_draft", "node"], startJobsResponse) || nodeUrl;
|
|
313
|
+
|
|
314
|
+
logger.data("library_id", libraryId);
|
|
315
|
+
logger.data("object_id", id);
|
|
316
|
+
logger.data("offering_key", offeringKey);
|
|
317
|
+
logger.data("write_token", lroWriteToken);
|
|
318
|
+
logger.data("write_node", lroNode);
|
|
319
|
+
logger.data("node_endpoint", lroNode);
|
|
320
|
+
|
|
321
|
+
logger.logList(
|
|
322
|
+
"",
|
|
323
|
+
`Library ID: ${libraryId}`,
|
|
324
|
+
`Object ID: ${id}`,
|
|
325
|
+
`Variant: ${variantKey}`,
|
|
326
|
+
`Offering: ${offeringKey}`,
|
|
327
|
+
`Write Token: ${lroWriteToken}`,
|
|
328
|
+
`Write Node: ${lroNode}`,
|
|
329
|
+
""
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
SetStatus({state: "mez_started", mez_started: true, mez_job: startJobsResponse});
|
|
333
|
+
|
|
334
|
+
logger.log("Progress:");
|
|
335
|
+
|
|
336
|
+
const lro = this.concerns.LRO;
|
|
337
|
+
let done = false;
|
|
338
|
+
let lastStatus;
|
|
339
|
+
while(!done) {
|
|
340
|
+
const statusMap = await lro.status({libraryId, objectId: id, writeToken}); // TODO: check how offering key is used, if at all
|
|
341
|
+
const statusSummary = lro.statusSummary(statusMap);
|
|
342
|
+
lastStatus = statusSummary.run_state;
|
|
343
|
+
if(lastStatus !== LRO.STATE_RUNNING) done = true;
|
|
344
|
+
logger.log(`run_state: ${lastStatus}`);
|
|
345
|
+
const eta = statusSummary.estimated_time_left_h_m_s;
|
|
346
|
+
if(eta) logger.log(`estimated time left: ${eta}`);
|
|
347
|
+
await seconds(15);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const finalizeAbrResponse = await client.FinalizeABRMezzanine({
|
|
351
|
+
libraryId,
|
|
352
|
+
objectId: id,
|
|
353
|
+
writeToken,
|
|
354
|
+
offeringKey
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
logger.errorsAndWarnings(finalizeAbrResponse);
|
|
358
|
+
const finalizeErrors = finalizeAbrResponse.errors;
|
|
359
|
+
if(!R.isNil(finalizeErrors) && !R.isEmpty(finalizeErrors)) throw Error(`Error(s) encountered while finalizing object: ${finalizeErrors.join("\n")}`);
|
|
360
|
+
|
|
361
|
+
if(s3Reference) {
|
|
362
|
+
logger.log("Retaining S3 source file reference.");
|
|
363
|
+
} else {
|
|
364
|
+
logger.log("Deleting source files...");
|
|
365
|
+
await client.DeleteFiles({
|
|
366
|
+
libraryId,
|
|
367
|
+
objectId: id,
|
|
368
|
+
writeToken,
|
|
369
|
+
filePaths: fileInfo.map(f => f.path)
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
nodeUrl = client.WriteTokenNodeUrlLocal({writeToken}) || nodeUrl;
|
|
373
|
+
|
|
374
|
+
let latestHash = "not finalized";
|
|
375
|
+
|
|
376
|
+
if(noFinalize) {
|
|
377
|
+
logger.log("Skipping content object finalization (--no-finalize).");
|
|
378
|
+
} else {
|
|
379
|
+
logger.log("Finalizing content object...");
|
|
380
|
+
const sourceFileName = fileInfo[0].path.split("/").pop();
|
|
381
|
+
const finalizeObjResponse = await client.FinalizeContentObject({
|
|
382
|
+
libraryId,
|
|
383
|
+
objectId: id,
|
|
384
|
+
writeToken,
|
|
385
|
+
commitMessage: `Ingest ${sourceFileName}${hdrInfoFile ? " [HDR]" : ""}`
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
latestHash = finalizeObjResponse.hash;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
logger.data("version_hash", latestHash);
|
|
392
|
+
logger.data("write_token", writeToken);
|
|
393
|
+
logger.data("write_node", nodeUrl);
|
|
394
|
+
logger.data("node_endpoint", nodeUrl);
|
|
395
|
+
|
|
396
|
+
logger.logList(
|
|
397
|
+
"",
|
|
398
|
+
noFinalize ? "Playable media object draft prepared:" : "Playable media object created:",
|
|
399
|
+
` Object ID: ${id}`,
|
|
400
|
+
` Version Hash: ${latestHash}`,
|
|
401
|
+
` Write Token: ${writeToken}`,
|
|
402
|
+
` Node Endpoint: ${nodeUrl}`,
|
|
403
|
+
""
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if(!noFinalize) {
|
|
407
|
+
await this.concerns.Finalize.waitForPublish({
|
|
408
|
+
latestHash,
|
|
409
|
+
libraryId,
|
|
410
|
+
objectId: id
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
header() {
|
|
416
|
+
return "Create playable media object via media ingest";
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if(require.main === module) {
|
|
421
|
+
Utility.cmdLineInvoke(MediaIngest);
|
|
422
|
+
} else {
|
|
423
|
+
module.exports = MediaIngest;
|
|
424
|
+
}
|