@dolbyio/dolbyio-rest-apis-client 3.5.1 → 3.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -116,9 +116,11 @@ console.log(subscribeToken);
116
116
 
117
117
  ## Media Examples
118
118
 
119
- ### Start an enhance job
119
+ Here is an example on how to upload a file to the Dolby.io temporary cloud storage, enhance that file and download the result.
120
+
121
+ ### Get an API token
120
122
 
121
- To start an enhance job, use the following code:
123
+ Get the App Key and Secret from the Dolby.io dashboard and use the following code in your python script.
122
124
 
123
125
  ```javascript
124
126
  const dolbyio = require('@dolbyio/dolbyio-rest-apis-client');
@@ -128,18 +130,72 @@ const APP_SECRET = 'YOUR_APP_SECRET';
128
130
 
129
131
  // Request an Access Token
130
132
  const jwt = await dolbyio.authentication.getApiAccessToken(APP_KEY, APP_SECRET);
133
+ console.log('Access token', jwt);
134
+ ```
135
+
136
+ ### Upload a file for processing
137
+
138
+ Upload a media file to the Dolby.io temporary cloud storage for processing:
139
+
140
+ ```javascript
141
+ // Temporary storage URL that will be used as reference for the job processing
142
+ const inputUrl = 'dlb://in/file.mp4';
143
+ // Local path of the file to upload
144
+ const originalFilePath = '/path/to/original_file.mp4';
145
+
146
+ await dolbyio.io.uploadFile(jwt, inputUrl, originalFilePath);
147
+ ```
148
+
149
+ ### Start an enhance job
150
+
151
+ Generate a job description and send it to Dolby.io.
152
+
153
+ ```javascript
154
+ // Temporary storage URL that will be used as reference for the job processing
155
+ const outputUrl = 'dlb://out/file.mp4';
131
156
 
132
157
  const jobDescription = JSON.stringify({
133
158
  content: { type: 'podcast' },
134
- input: 'dlb://in/file.mp4',
135
- output: 'dlb://out/file.mp4',
159
+ input: inputUrl,
160
+ output: outputUrl,
136
161
  });
137
162
 
138
163
  const jobId = await dolbyio.media.enhance.start(jwt, jobDescription);
139
-
140
164
  console.log(`Job ID: ${jobId}`);
141
165
  ```
142
166
 
167
+ ### Wait for the job to complete
168
+
169
+ Get the job status and wait until it is completed.
170
+
171
+ ```javascript
172
+ const sleep = (delay) => new Promise((r) => setTimeout(r, delay));
173
+
174
+ let result = await dolbyio.media.enhance.getResults(jwt, jobId);
175
+ while (result.status === 'Pending' || result.status === 'Running') {
176
+ console.log(`Job status is ${result.status}, taking a 5 second break...`);
177
+ await sleep(5000);
178
+
179
+ result = await dolbyio.media.enhance.getResults(jwt, jobId);
180
+ }
181
+
182
+ if (result.status !== 'Success') {
183
+ console.error('There was a problem with processing the file', result);
184
+ return;
185
+ }
186
+ ```
187
+
188
+ ### Download a processed file
189
+
190
+ At this stage, the file has been processed and written to the temporary storage so we can download it.
191
+
192
+ ```javascript
193
+ // Local path where to download the file to
194
+ const enhancedFilePath = '/path/to/enhanced_file.mp4';
195
+
196
+ await dolbyio.io.downloadFile(jwt, outputUrl, enhancedFilePath);
197
+ ```
198
+
143
199
  ## Build this project
144
200
 
145
201
  To build the `dist` folder, run the command:
package/dist/index.js CHANGED
@@ -15,5 +15,5 @@ var streaming = _interopRequireWildcard(require("./streaming"));
15
15
  exports.streaming = streaming;
16
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
17
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
- var version = "3.5.1";
18
+ var version = "3.5.2";
19
19
  exports.version = version;
@@ -55,3 +55,10 @@ export declare const sendPatch: (options: RequestOptions) => Promise<any>;
55
55
  * @param options Request options.
56
56
  */
57
57
  export declare const download: (filepath: string, options: RequestOptions) => Promise<void>;
58
+ /**
59
+ * Upload a file.
60
+ *
61
+ * @param filepath The local path of the file to upload.
62
+ * @param uploadUrl Where to upload the file to.
63
+ */
64
+ export declare const upload: (filepath: string, uploadUrl: string) => Promise<void>;
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.sendPut = exports.sendPost = exports.sendPatch = exports.sendGet = exports.sendDelete = exports.download = void 0;
6
+ exports.upload = exports.sendPut = exports.sendPost = exports.sendPatch = exports.sendGet = exports.sendDelete = exports.download = void 0;
7
7
  var _fs = _interopRequireDefault(require("fs"));
8
8
  var _followRedirects = require("follow-redirects");
9
+ var _https = _interopRequireDefault(require("https"));
9
10
  var _url = require("url");
10
11
  var _index = require("../index");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -250,4 +251,39 @@ var download = function download(filepath, options) {
250
251
  req.end();
251
252
  });
252
253
  };
253
- exports.download = download;
254
+
255
+ /**
256
+ * Upload a file.
257
+ *
258
+ * @param filepath The local path of the file to upload.
259
+ * @param uploadUrl Where to upload the file to.
260
+ */
261
+ exports.download = download;
262
+ var upload = function upload(filepath, uploadUrl) {
263
+ // Get the size of the file to upload
264
+ var fileSize = _fs["default"].statSync(filepath).size;
265
+ return new Promise(function (resolve, reject) {
266
+ var opts = {
267
+ method: 'PUT',
268
+ headers: {
269
+ "Content-Length": fileSize
270
+ }
271
+ };
272
+ var req = _https["default"].request(uploadUrl, opts, function (res) {
273
+ console.log("[".concat(opts.method, "] ").concat(res.statusCode, " - ").concat(uploadUrl));
274
+ if (res.statusCode < 200 || res.statusCode >= 400) {
275
+ reject('This request has been rejected with the response code ' + res.statusCode);
276
+ } else {
277
+ resolve();
278
+ }
279
+ });
280
+ req.on('error', function (error) {
281
+ console.error(error);
282
+ reject(error);
283
+ });
284
+
285
+ // Start the upload of the file
286
+ _fs["default"].createReadStream(filepath).pipe(req);
287
+ });
288
+ };
289
+ exports.upload = upload;
@@ -31,6 +31,18 @@ export declare const getUploadUrl: (accessToken: JwtToken, dlbUrl: string) => Pr
31
31
  * @returns The download URL through a {@link Promise}.
32
32
  */
33
33
  export declare const getDownloadUrl: (accessToken: JwtToken, dlbUrl: string) => Promise<string | null>;
34
+ /**
35
+ * Upload a media file to the Dolby.io temporary storage.
36
+ *
37
+ * The temporary storage should allow you to read and write to the dlb:// locations for a period of at least 24 hours before it is removed.
38
+ *
39
+ * @link https://docs.dolby.io/media-apis/reference/media-input-post
40
+ *
41
+ * @param accessToken Access token to use for authentication.
42
+ * @param dlbUrl The `url` should be in the form `dlb://object-key` where the object-key can be any alpha-numeric string. The object-key is unique to your account API Key so there is no risk of collision with other users.
43
+ * @param filePath Local path of the file you want to upload.
44
+ */
45
+ export declare const uploadFile: (accessToken: JwtToken, dlbUrl: string, filePath: string) => Promise<void>;
34
46
  /**
35
47
  * Download a media file.
36
48
  *
package/dist/media/io.js CHANGED
@@ -4,7 +4,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getUploadUrl = exports.getDownloadUrl = exports.downloadFile = void 0;
7
+ exports.uploadFile = exports.getUploadUrl = exports.getDownloadUrl = exports.downloadFile = void 0;
8
8
  var _httpHelpers = require("./internal/httpHelpers");
9
9
  var _httpHelpers2 = require("../internal/httpHelpers");
10
10
  var _urls = require("./internal/urls");
@@ -129,6 +129,42 @@ var getDownloadUrl = /*#__PURE__*/function () {
129
129
  };
130
130
  }();
131
131
 
132
+ /**
133
+ * Upload a media file to the Dolby.io temporary storage.
134
+ *
135
+ * The temporary storage should allow you to read and write to the dlb:// locations for a period of at least 24 hours before it is removed.
136
+ *
137
+ * @link https://docs.dolby.io/media-apis/reference/media-input-post
138
+ *
139
+ * @param accessToken Access token to use for authentication.
140
+ * @param dlbUrl The `url` should be in the form `dlb://object-key` where the object-key can be any alpha-numeric string. The object-key is unique to your account API Key so there is no risk of collision with other users.
141
+ * @param filePath Local path of the file you want to upload.
142
+ */
143
+ exports.getDownloadUrl = getDownloadUrl;
144
+ var uploadFile = /*#__PURE__*/function () {
145
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(accessToken, dlbUrl, filePath) {
146
+ var uploadUrl;
147
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
148
+ while (1) {
149
+ switch (_context4.prev = _context4.next) {
150
+ case 0:
151
+ _context4.next = 2;
152
+ return getUploadUrl(accessToken, dlbUrl);
153
+ case 2:
154
+ uploadUrl = _context4.sent;
155
+ return _context4.abrupt("return", (0, _httpHelpers2.upload)(filePath, uploadUrl));
156
+ case 4:
157
+ case "end":
158
+ return _context4.stop();
159
+ }
160
+ }
161
+ }, _callee4);
162
+ }));
163
+ return function uploadFile(_x8, _x9, _x10) {
164
+ return _ref4.apply(this, arguments);
165
+ };
166
+ }();
167
+
132
168
  /**
133
169
  * Download a media file.
134
170
  *
@@ -142,18 +178,18 @@ var getDownloadUrl = /*#__PURE__*/function () {
142
178
  * @param dlbUrl The `url` should be in the form `dlb://object-key` where the object-key can be any alpha-numeric string. The object-key is unique to your account API Key so there is no risk of collision with other users.
143
179
  * @param filePath Local file path where to download the file to.
144
180
  */
145
- exports.getDownloadUrl = getDownloadUrl;
181
+ exports.uploadFile = uploadFile;
146
182
  var downloadFile = /*#__PURE__*/function () {
147
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(accessToken, dlbUrl, filePath) {
183
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(accessToken, dlbUrl, filePath) {
148
184
  var downloadUrl, idx, requestOptions;
149
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
185
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
150
186
  while (1) {
151
- switch (_context4.prev = _context4.next) {
187
+ switch (_context5.prev = _context5.next) {
152
188
  case 0:
153
- _context4.next = 2;
189
+ _context5.next = 2;
154
190
  return getDownloadUrl(accessToken, dlbUrl);
155
191
  case 2:
156
- downloadUrl = _context4.sent;
192
+ downloadUrl = _context5.sent;
157
193
  downloadUrl = downloadUrl.replace('https://', '');
158
194
  idx = downloadUrl.indexOf('/');
159
195
  requestOptions = {
@@ -161,16 +197,16 @@ var downloadFile = /*#__PURE__*/function () {
161
197
  path: downloadUrl.substring(idx + 1),
162
198
  headers: {}
163
199
  };
164
- return _context4.abrupt("return", (0, _httpHelpers2.download)(filePath, requestOptions));
200
+ return _context5.abrupt("return", (0, _httpHelpers2.download)(filePath, requestOptions));
165
201
  case 7:
166
202
  case "end":
167
- return _context4.stop();
203
+ return _context5.stop();
168
204
  }
169
205
  }
170
- }, _callee4);
206
+ }, _callee5);
171
207
  }));
172
- return function downloadFile(_x8, _x9, _x10) {
173
- return _ref4.apply(this, arguments);
208
+ return function downloadFile(_x11, _x12, _x13) {
209
+ return _ref5.apply(this, arguments);
174
210
  };
175
211
  }();
176
212
  exports.downloadFile = downloadFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolbyio/dolbyio-rest-apis-client",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "description": "Node.JS wrapper for the dolby.io REST APIs",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,6 +13,15 @@
13
13
  },
14
14
  "author": "Fabien Lavocat <fabien.lavocat@dolby.com>",
15
15
  "license": "MIT",
16
+ "keywords": [
17
+ "nodejs",
18
+ "api",
19
+ "sdk",
20
+ "rest",
21
+ "rest-api",
22
+ "webrtc",
23
+ "dolbyio"
24
+ ],
16
25
  "files": [
17
26
  "dist/*",
18
27
  "README.md"