From 0f1197138e3aae2d9cc25f3f1d3c6c3d7a235422 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 15 Oct 2019 18:13:40 -0300 Subject: Open JSON playlist files in new tab --- general-util.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'general-util.js') diff --git a/general-util.js b/general-util.js index a7bfb11..3aa4180 100644 --- a/general-util.js +++ b/general-util.js @@ -3,6 +3,7 @@ const { promisify } = require('util') const fetch = require('node-fetch') const fs = require('fs') const npmCommandExists = require('command-exists') +const url = require('url') const readFile = promisify(fs.readFile) @@ -61,9 +62,19 @@ function downloadPlaylistFromLocalPath(path) { } module.exports.downloadPlaylistFromOptionValue = function(arg) { - // TODO: Verify things! - if (arg.startsWith('http://') || arg.startsWith('https://')) { - return downloadPlaylistFromURL(arg) + let argURL + try { + argURL = new url.URL(arg) + } catch (err) { + // Definitely not a URL. + } + + if (argURL) { + if (argURL.protocol === 'http:' || argURL.protocol === 'https:') { + return downloadPlaylistFromURL(arg) + } else if (argURL.protocol === 'file:') { + return downloadPlaylistFromLocalPath(url.fileURLToPath(argURL)) + } } else { return downloadPlaylistFromLocalPath(arg) } -- cgit 1.3.0-6-gf8a5