« get me outta code hell

Update HTTP crawler to use Playlist 2.0 format - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-07-15 18:20:52 -0400
committerLiam <towerofnix@gmail.com>2017-07-15 18:20:52 -0400
commitced15bbbfad358db206e84f0a5ca101d32d504c5 (patch)
treeb7503d3cc8287a924f693731c705883ce1ba889b /src
parentacda732cc57ead57c203c1cde1b040026c4ccaa2 (diff)
Update HTTP crawler to use Playlist 2.0 format
Diffstat (limited to 'src')
-rwxr-xr-xsrc/crawl-http.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/crawl-http.js b/src/crawl-http.js
index 020506b..a2bf884 100755
--- a/src/crawl-http.js
+++ b/src/crawl-http.js
@@ -18,7 +18,7 @@ function crawl(absURL, opts = {}, internals = {}) {
 
     maxAttempts = 5,
 
-    keepSeparateHosts = true,
+    keepSeparateHosts = false,
 
     keepAnyFileType = false,
     fileTypes = ['wav', 'ogg', 'oga', 'mp3', 'mp4', 'm4a', 'mov'],
@@ -27,6 +27,10 @@ function crawl(absURL, opts = {}, internals = {}) {
   } = opts
 
   if (!internals.attempts) internals.attempts = 0
+
+  // TODO: Should absURL initially be added into this array? I'd like to
+  // re-program this entire crawl function to make more sense - "internal"
+  // dictionaries aren't quite easy to reason about!
   if (!internals.allURLs) internals.allURLs = []
 
   const verboseLog = text => {
@@ -43,7 +47,7 @@ function crawl(absURL, opts = {}, internals = {}) {
         const links = getHTMLLinks(text)
 
         return Promise.all(links.map(link => {
-          const [ title, href ] = link
+          const [ name, href ] = link
           const urlObj = new url.URL(href, absURL)
           const linkURL = url.format(urlObj)
 
@@ -73,7 +77,7 @@ function crawl(absURL, opts = {}, internals = {}) {
             verboseLog("[Dir] " + linkURL)
 
             return crawl(linkURL, opts, Object.assign({}, internals))
-              .then(res => [title, res])
+              .then(items => ({name, items}))
           } else {
             // It's a file!
 
@@ -89,9 +93,9 @@ function crawl(absURL, opts = {}, internals = {}) {
             }
 
             verboseLog("[File] " + linkURL)
-            return Promise.resolve([title, linkURL])
+            return Promise.resolve({name, downloaderArg: linkURL})
           }
-        }).filter(Boolean))
+        }).filter(Boolean)).then(items => ({items}))
       }),
 
       err => {