diff options
-rw-r--r-- | man/http-music.1 | 2 | ||||
-rwxr-xr-x | src/http-music.js | 33 |
2 files changed, 30 insertions, 5 deletions
diff --git a/man/http-music.1 b/man/http-music.1 index 751a397..741ff8b 100644 --- a/man/http-music.1 +++ b/man/http-music.1 @@ -99,7 +99,7 @@ Opens a specific file to be used as the playlist file. The default playlist file used upon loading is playlist.json (in the same directory as \fBhttp-music\fR is being run in). .TP -.BR \-\-picker " \fIpickerType\fR" +.BR \-\-picker ", " \-\-selector " \fIpickerType\fR" Sets the picker type used for selecting tracks from the active playlist. The default is \fBshuffle\fR. diff --git a/src/http-music.js b/src/http-music.js index e926e5d..bcd4672 100755 --- a/src/http-music.js +++ b/src/http-music.js @@ -7,6 +7,7 @@ const fs = require('fs') const pickers = require('./pickers') const loopPlay = require('./loop-play') const processArgv = require('./process-argv') +const fetch = require('node-fetch') const { filterPlaylistByPathString, removeGroupByPathString, getPlaylistTreeString @@ -14,6 +15,23 @@ const { const readFile = promisify(fs.readFile) +function downloadPlaylistFromURL(url) { + return fetch(url).then(res => res.text()) +} + +function downloadPlaylistFromLocalPath(path) { + return readFile(path) +} + +function downloadPlaylistFromOptionValue(arg) { + // TODO: Verify things! + if (arg.startsWith('http://') || arg.startsWith('https://')) { + return downloadPlaylistFromURL(arg) + } else { + return downloadPlaylistFromLocalPath(arg) + } +} + Promise.resolve() .then(async () => { let sourcePlaylist = null @@ -28,14 +46,19 @@ Promise.resolve() let shouldPlay = true let willPlay = null - async function openPlaylist(file, silent = false) { + async function openPlaylist(arg, silent = false) { let playlistText + if (!silent) { + console.log("Opening playlist from: " + arg) + } + try { - playlistText = await readFile(file, 'utf-8') + playlistText = await downloadPlaylistFromOptionValue(arg) } catch(err) { if (!silent) { - console.error("Failed to read playlist file: " + file) + console.error("Failed to open playlist file: " + arg) + console.error(err) } return false @@ -210,13 +233,15 @@ Promise.resolve() 'np': util => util.alias('-no-play'), '-picker': function(util) { - // --picker <picker type> + // --picker <picker type> (alias: --selector) // Selects the mode that the song to play is picked. // See pickers.js. pickerType = util.nextArg() }, + '-selector': util => util.alias('-picker'), + '-play-opts': function(util) { // --play-opts <opts> // Sets command line options passed to the `play` command. |