« get me outta code hell

Smart playlists - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/general-util.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-04 21:27:18 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-04 21:27:20 -0300
commit6055638558a345904b41467839191a7143862d25 (patch)
tree9b192640b171f48282650903b398084f24481507 /general-util.js
parent6d270d43d5f09108132557100065fab3c0d34afc (diff)
Smart playlists
Basically directly pulled from http-music. Want to make a nice UI for
this eventually ("opening playlist..." popup dialog), but not for now.
Diffstat (limited to 'general-util.js')
-rw-r--r--general-util.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/general-util.js b/general-util.js
index 35e1103..879219d 100644
--- a/general-util.js
+++ b/general-util.js
@@ -46,3 +46,20 @@ module.exports.killProcess = async function(proc) {
     proc.kill()
   }
 }
+
+function downloadPlaylistFromURL(url) {
+  return fetch(url).then(res => res.text())
+}
+
+function downloadPlaylistFromLocalPath(path) {
+  return readFile(path).then(buf => buf.toString())
+}
+
+module.exports.downloadPlaylistFromOptionValue = function(arg) {
+  // TODO: Verify things!
+  if (arg.startsWith('http://') || arg.startsWith('https://')) {
+    return downloadPlaylistFromURL(arg)
+  } else {
+    return downloadPlaylistFromLocalPath(arg)
+  }
+}