From c41b0bbb11b06544d696656b9ef441604b6b28c1 Mon Sep 17 00:00:00 2001 From: liam4 Date: Thu, 1 Jun 2017 16:17:46 -0300 Subject: YouTube downloader --- src/play.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/play.js') diff --git a/src/play.js b/src/play.js index 0ffe996..38b05d5 100755 --- a/src/play.js +++ b/src/play.js @@ -7,6 +7,8 @@ const fs = require('fs') const { promisify } = require('util') const loopPlay = require('./loop-play') const processArgv = require('./process-argv') + +const downloaders = require('./downloaders') const pickers = require('./pickers') const { @@ -22,6 +24,7 @@ readFile('./playlist.json', 'utf-8') let curPlaylist = playlist let pickerType = 'shuffle' + let downloaderType = 'http' let playOpts = [] // WILL play says whether the user has forced playback via an argument. @@ -132,14 +135,21 @@ readFile('./playlist.json', 'utf-8') 'np': util => util.alias('-no-play'), '-picker': function(util) { - // --picker + // --picker // Selects the mode that the song to play is picked. - // This should be used after finishing modifying the active - // playlist. + // See pickers.js. pickerType = util.nextArg() }, + '-downloader': function(util) { + // --downloader + // Selects the mode that songs will be downloaded with. + // See downloaders.js. + + downloaderType = util.nextArg() + }, + '-play-opts': function(util) { // --play-opts // Sets command line options passed to the `play` command. @@ -165,9 +175,22 @@ readFile('./playlist.json', 'utf-8') picker = pickers.makeOrderedPlaylistPicker(curPlaylist) } else { console.error("Invalid picker type: " + pickerType) + return + } + + let downloader + if (downloaderType === 'http') { + console.log("Using HTTP downloader.") + downloader = downloaders.makeHTTPDownloader() + } else if (downloaderType === 'youtube') { + console.log("Using YouTube downloader.") + downloader = downloaders.makeYouTubeDownloader() + } else { + console.error("Invalid downloader type: " + downloaderType) + return } - return loopPlay(picker, playOpts) + return loopPlay(picker, downloader, playOpts) } else { return curPlaylist } -- cgit 1.3.0-6-gf8a5