index.js 782 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. const deezerApi = require('deezer-request2');
  7. /**
  8. * Start a deezer download.from module
  9. *
  10. * @param {String} deezerUrl
  11. */
  12. const dFi = async (deezerUrl, path = defaults.DOWNLOAD_DIR, quality = musicQualities.selectedQuality.id) => {
  13. try {
  14. const downloadType = await downloadTypes(deezerUrl);
  15. if (downloadType.type == 'unknown') {
  16. throw { error: 'Invalid url', message: 'Unknown url type' };
  17. }
  18. return downloadMultiple(downloadType, path, quality);
  19. } catch (err) {
  20. return err;
  21. }
  22. };
  23. module.exports = { dFi, deezerApi };