« get me outta code hell

Update JS to have one main http-music command - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/download-playlist.js
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-07-20 18:55:18 -0300
committerliam4 <towerofnix@gmail.com>2017-07-20 18:55:18 -0300
commit1a02fe1688d66aea6277f61fcc305a6aed4e7d76 (patch)
tree6e64e928acf81af89fd7f0e802d94eb0c844a63e /src/download-playlist.js
parent2680ea9126499fb775b699f1dbd4ac9aacbc4e4a (diff)
Update JS to have one main http-music command
Diffstat (limited to 'src/download-playlist.js')
-rwxr-xr-xsrc/download-playlist.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/download-playlist.js b/src/download-playlist.js
index 18e1a7f..0b5ea58 100755
--- a/src/download-playlist.js
+++ b/src/download-playlist.js
@@ -102,17 +102,15 @@ async function downloadCrawl(topPlaylist, initialOutPath = './out/') {
   return recursive(topPlaylist.items, initialOutPath)
 }
 
-async function main() {
+async function main(args) {
   // TODO: Implement command line stuff here
 
-  if (process.argv.length === 2) {
+  if (args.length === 0) {
     console.error('Usage: download-playlist <playlistFile> [opts]')
     return
   }
 
-  const playlist = updatePlaylistFormat(
-    JSON.parse(await readFile(process.argv[2]))
-  )
+  const playlist = updatePlaylistFormat(JSON.parse(await readFile(args[0])))
 
   const outPlaylist = await downloadCrawl(playlist)
 
@@ -122,5 +120,7 @@ async function main() {
   process.exit(0)
 }
 
-main()
-  .catch(err => console.error(err))
+if (require.main === module) {
+  main(process.argv.slice(2))
+    .catch(err => console.error(err))
+}