« get me outta code hell

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:
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)
+  }
+}