diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/downloaders.js | 8 | ||||
-rw-r--r-- | src/loop-play.js | 22 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/downloaders.js b/src/downloaders.js index aa0bc44..b9cc33d 100644 --- a/src/downloaders.js +++ b/src/downloaders.js @@ -122,6 +122,14 @@ module.exports = { makePowerfulDownloader, makeConverterDownloader, + byName: { + 'http': makeHTTPDownloader, + 'local': makeLocalDownloader, + 'file': makeLocalDownloader, + 'youtube': makeYouTubeDownloader, + 'youtube-dl': makeYouTubeDownloader + }, + getDownloaderFor(arg) { if (arg.startsWith('http://') || arg.startsWith('https://')) { if (arg.includes('youtube.com')) { diff --git a/src/loop-play.js b/src/loop-play.js index b0bb4dd..9328073 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -5,7 +5,10 @@ const { spawn } = require('child_process') const FIFO = require('fifo-js') const EventEmitter = require('events') -const { getDownloaderFor, makeConverterDownloader } = require('./downloaders') +const { + getDownloaderFor, makeConverterDownloader, + byName: downloadersByName +} = require('./downloaders') const { getItemPathString } = require('./playlist-utils') const promisifyProcess = require('./promisify-process') @@ -114,7 +117,22 @@ class PlayController { if (picked === null) { return null } else { - let downloader = getDownloaderFor(picked.downloaderArg) + let downloader + + if (picked.downloader) { + downloader = downloadersByName[picked.downloader]() + + if (!downloader) { + console.error( + `Invalid downloader for track ${picked.name}:`, downloader + ) + + return false + } + } else { + downloader = getDownloaderFor(picked.downloaderArg) + } + downloader = makeConverterDownloader(downloader, 'wav') this.downloadController.download(downloader, picked.downloaderArg) return picked |