diff options
-rw-r--r-- | src/downloaders.js | 8 | ||||
-rw-r--r-- | src/loop-play.js | 22 | ||||
-rw-r--r-- | todo.txt | 5 |
3 files changed, 33 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 diff --git a/todo.txt b/todo.txt index c16f680..030862e 100644 --- a/todo.txt +++ b/todo.txt @@ -235,3 +235,8 @@ TODO: The filter utility function shouldn't work at all if it fails to find TODO: Make the filter/remove/keep options do a search of some sort. TODO: Make those options also work with tracks! + +TODO: The URL 'http://somesite.com/youtube.com.mp3' would probably + automatically assume the YouTube downloader. Instead of checking for the + string 'youtube.com' included in the downloader arg, check if it is a + valid URL and that the URL's domain is 'youtube.com'. |