index.js 722 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const defaults = require('./src/defaults');
  3. const musicQualities = require('./src/musicQualities');
  4. const downloadTypes = require('./src/downloadTypes');
  5. const downloadMultiple = require('./src/downloadMultiple');
  6. /**
  7. * Start a deezer download.from module
  8. *
  9. * @param {String} deezerUrl
  10. */
  11. const dFi = async (deezerUrl, path = defaults.DOWNLOAD_DIR, quality = musicQualities.selectedQuality.id) => {
  12. try {
  13. const downloadType = await downloadTypes(deezerUrl);
  14. if (downloadType.type == 'unknown') {
  15. throw { error: 'Invalid url', message: 'Unknown url type' };
  16. }
  17. return downloadMultiple(downloadType, path, quality);
  18. } catch (err) {
  19. return err;
  20. }
  21. };
  22. module.exports = dFi;