Newer
Older
CVSS_3.0_GUI / dist / CVSS_3.0_Calc-1.0.0-linux-x64 / node_modules / nwjs-builder-phoenix / dist / lib / FFmpegDownloader.js
root on 7 May 2019 7 KB Initial commit
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  13. return new (P || (P = Promise))(function (resolve, reject) {
  14. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  15. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  16. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  17. step((generator = generator.apply(thisArg, _arguments || [])).next());
  18. });
  19. };
  20. var __generator = (this && this.__generator) || function (thisArg, body) {
  21. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  22. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  23. function verb(n) { return function (v) { return step([n, v]); }; }
  24. function step(op) {
  25. if (f) throw new TypeError("Generator is already executing.");
  26. while (_) try {
  27. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  28. if (y = 0, t) op = [0, t.value];
  29. switch (op[0]) {
  30. case 0: case 1: t = op; break;
  31. case 4: _.label++; return { value: op[1], done: false };
  32. case 5: _.label++; y = op[1]; op = [0]; continue;
  33. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  34. default:
  35. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  36. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  37. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  38. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  39. if (t[2]) _.ops.pop();
  40. _.trys.pop(); continue;
  41. }
  42. op = body.call(thisArg, _);
  43. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  44. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  45. }
  46. };
  47. Object.defineProperty(exports, "__esModule", { value: true });
  48. var path_1 = require("path");
  49. var debug = require('debug')('build:ffmpegDownloader');
  50. var progress = require('request-progress');
  51. var common_1 = require("./common");
  52. var util_1 = require("./util");
  53. var FFmpegDownloader = /** @class */ (function (_super) {
  54. __extends(FFmpegDownloader, _super);
  55. function FFmpegDownloader(options) {
  56. var _this = _super.call(this) || this;
  57. _this.options = util_1.mergeOptions(FFmpegDownloader.DEFAULT_OPTIONS, options);
  58. debug('in constructor', 'options', options);
  59. return _this;
  60. }
  61. FFmpegDownloader.prototype.fetch = function () {
  62. return __awaiter(this, void 0, void 0, function () {
  63. var _a, mirror, version, platform, arch, showProgress, partVersion, partPlatform, partArch, url, filename, path, _b, err_1;
  64. return __generator(this, function (_c) {
  65. switch (_c.label) {
  66. case 0:
  67. _a = this.options, mirror = _a.mirror, version = _a.version, platform = _a.platform, arch = _a.arch, showProgress = _a.showProgress;
  68. return [4 /*yield*/, this.handleVersion(version)];
  69. case 1:
  70. partVersion = _c.sent();
  71. partPlatform = this.handlePlatform(platform);
  72. partArch = this.handleArch(arch);
  73. url = mirror + "/" + partVersion + "/" + partVersion + "-" + partPlatform + "-" + partArch + ".zip";
  74. filename = "ffmpeg-" + path_1.basename(url);
  75. path = path_1.resolve(this.destination, filename);
  76. debug('in fetch', 'url', url);
  77. debug('in fetch', 'filename', filename);
  78. debug('in fetch', 'path', path);
  79. _c.label = 2;
  80. case 2:
  81. _c.trys.push([2, 6, , 7]);
  82. return [4 /*yield*/, this.isFileExists(path)];
  83. case 3:
  84. _b = (_c.sent());
  85. if (!_b) return [3 /*break*/, 5];
  86. return [4 /*yield*/, this.isFileSynced(url, path)];
  87. case 4:
  88. _b = (_c.sent());
  89. _c.label = 5;
  90. case 5:
  91. if (_b) {
  92. return [2 /*return*/, path];
  93. }
  94. return [3 /*break*/, 7];
  95. case 6:
  96. err_1 = _c.sent();
  97. debug('in fetch', 'err', err_1);
  98. if (err_1.code === 'ENOTFOUND' && this.options.useCaches) {
  99. console.info('DNS lookup fails, use local caches at this time.');
  100. return [2 /*return*/, path];
  101. }
  102. else if (err_1.code === 'EAI_AGAIN' && this.options.useCaches) {
  103. console.info('DNS lookup timeout, use local caches at this time.');
  104. return [2 /*return*/, path];
  105. }
  106. else {
  107. throw err_1;
  108. }
  109. return [3 /*break*/, 7];
  110. case 7: return [4 /*yield*/, this.download(url, filename, path, showProgress)];
  111. case 8:
  112. _c.sent();
  113. return [2 /*return*/, path];
  114. }
  115. });
  116. });
  117. };
  118. FFmpegDownloader.prototype.handleVersion = function (version) {
  119. return __awaiter(this, void 0, void 0, function () {
  120. return __generator(this, function (_a) {
  121. switch (version) {
  122. case 'lts':
  123. case 'stable':
  124. case 'latest':
  125. throw new Error('ERROR_VERSION_UNSUPPORTED');
  126. default:
  127. return [2 /*return*/, version[0] == 'v' ? version.slice(1) : version];
  128. }
  129. return [2 /*return*/];
  130. });
  131. });
  132. };
  133. FFmpegDownloader.DEFAULT_OPTIONS = {
  134. platform: process.platform,
  135. arch: process.arch,
  136. version: '0.14.7',
  137. mirror: 'https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases/download/',
  138. useCaches: true,
  139. showProgress: true,
  140. };
  141. return FFmpegDownloader;
  142. }(common_1.DownloaderBase));
  143. exports.FFmpegDownloader = FFmpegDownloader;
  144. //# sourceMappingURL=FFmpegDownloader.js.map
Buy Me A Coffee