« get me outta code hell

YouTube downloader - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/play.js
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-01 16:17:46 -0300
committerliam4 <towerofnix@gmail.com>2017-06-01 16:17:46 -0300
commitc41b0bbb11b06544d696656b9ef441604b6b28c1 (patch)
treea6c661fcc0341ddb460dfe133b11b5d834f54eb1 /src/play.js
parente302f04b782685847fd5ab72a1f968f6d03ccfe4 (diff)
YouTube downloader
Diffstat (limited to 'src/play.js')
-rwxr-xr-xsrc/play.js31
1 files changed, 27 insertions, 4 deletions
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 <shuffle|ordered>
+        // --picker <picker type>
         // 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 <downloader type>
+        // Selects the mode that songs will be downloaded with.
+        // See downloaders.js.
+
+        downloaderType = util.nextArg()
+      },
+
       '-play-opts': function(util) {
         // --play-opts <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
     }