From 507bd7b0c0f185a87b4213b5c95b3b3859fe9528 Mon Sep 17 00:00:00 2001 From: liam4 Date: Sun, 4 Jun 2017 10:05:15 -0300 Subject: Local file downloader --- src/downloaders.js | 19 ++++++++++++++++++- src/play.js | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/downloaders.js b/src/downloaders.js index 527f67d..3f3a427 100644 --- a/src/downloaders.js +++ b/src/downloaders.js @@ -33,4 +33,21 @@ function makeYouTubeDownloader() { } } -module.exports = {makeHTTPDownloader, makeYouTubeDownloader} +function makeLocalDownloader() { + return function(arg, out) { + const read = fs.createReadStream(arg) + const write = fs.createWriteStream(out) + + return new Promise((resolve, reject) => { + write.on('error', err => reject(err)) + write.on('close', () => resolve()) + read.pipe(write) + }) + } +} + +module.exports = { + makeHTTPDownloader, + makeYouTubeDownloader, + makeLocalDownloader +} diff --git a/src/play.js b/src/play.js index 38b05d5..bc9324d 100755 --- a/src/play.js +++ b/src/play.js @@ -185,6 +185,9 @@ readFile('./playlist.json', 'utf-8') } else if (downloaderType === 'youtube') { console.log("Using YouTube downloader.") downloader = downloaders.makeYouTubeDownloader() + } else if (downloaderType === 'local') { + console.log("Using local file downloader.") + downloader = downloaders.makeLocalDownloader() } else { console.error("Invalid downloader type: " + downloaderType) return -- cgit 1.3.0-6-gf8a5