misc.js 917 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*jshint node:true*/
  2. 'use strict';
  3. var path = require('path');
  4. /*
  5. *! Miscellaneous methods
  6. */
  7. module.exports = function(proto) {
  8. /**
  9. * Use preset
  10. *
  11. * @method FfmpegCommand#preset
  12. * @category Miscellaneous
  13. * @aliases usingPreset
  14. *
  15. * @param {String|Function} preset preset name or preset function
  16. */
  17. proto.usingPreset =
  18. proto.preset = function(preset) {
  19. if (typeof preset === 'function') {
  20. preset(this);
  21. } else {
  22. try {
  23. var modulePath = path.join(this.options.presets, preset);
  24. var module = require(modulePath);
  25. if (typeof module.load === 'function') {
  26. module.load(this);
  27. } else {
  28. throw new Error('preset ' + modulePath + ' has no load() function');
  29. }
  30. } catch (err) {
  31. throw new Error('preset ' + modulePath + ' could not be loaded: ' + err.message);
  32. }
  33. }
  34. return this;
  35. };
  36. };