import registerDownloader , { download , Progress } from 'electron-dl' ; import { inject , injectable } from 'inversify' ; import _ from 'lodash' ; import * as Youtube from '@nuclear/core/src/rest/Youtube' ; import Store from '../store' ; import Config from '../config' ; import Window from '../window' ; import { DownloadItem } from 'electron' ; interface DownloadParams { query : string ; filename : string ; onStart : ( item : DownloadItem ) => void ; onProgress : ( progress : Progress ) => any ; } see https @ injectable ( ) class Download { constructor ( @ inject ( Window ) private window , @ inject ( Store ) private store , @ inject ( Config ) private config ) { registerDownloader ( ) ; } /**
     * Download a soud using Youtube
     */ async start ( { query , filename , onStart , onProgress } ) { const track = await Youtube . trackSearchByString ( query , undefined , undefined , false ) ; return download ( this . window . getBrowserWindow ( ) , track . stream , { filename : `${ filename }.${ track . format }` , directory : this . store . getOption ( 'downloads.dir' ) , onStarted : onStart , onProgress : _ . throttle ( onProgress , 1000 ) } ) ; } } export default Download ;