From e447c564e9823a32c25aa1c9309c9b13d5225933 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 24 Oct 2017 17:33:22 -0300 Subject: Add --open-playlist-string option Lets playlists be passed to `play` by an actual string argument; e.g. --playlist-string '{"tracks": [...]}'. Could work well with http-music's own crawler utilities (e.g. --playlist-string '{"source": ["crawl-local", "."]}' or with external ones (e.g. --playlist-string "$(cool-crawler-utilith.sh)". At the moment the only workaround is to use a temporary file to store the playlist in, or to pipe the output of the crawler command (which might be `echo`!) to http-music and use /dev/stdin as the --playlist-file value.. which obviously isn't cross-platform or practical! I'd like to have some aliases in the future since --open-playlist-string isn't really easy to type. --- src/play.js | 22 +++++++++++++++++++++- todo.txt | 11 +++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/play.js b/src/play.js index 6d4456d..8f52e63 100755 --- a/src/play.js +++ b/src/play.js @@ -104,6 +104,9 @@ async function main(args) { ] async function openPlaylist(arg, silent = false) { + // Takes a playlist download argument and loads it as the source and + // active playlist. + let playlistText if (!silent) { @@ -121,7 +124,16 @@ async function main(args) { return false } - const openedPlaylist = updatePlaylistFormat(JSON.parse(playlistText)) + const importedPlaylist = JSON.parse(playlistText) + + await loadPlaylist(importedPlaylist) + } + + async function loadPlaylist(importedPlaylist) { + // Takes an actual playlist object and sets it up as the source and active + // playlist. + + const openedPlaylist = updatePlaylistFormat(importedPlaylist) // We also want to de-smart-ify (stupidify? - simplify?) the playlist. const processedPlaylist = await processSmartPlaylist(openedPlaylist) @@ -198,6 +210,14 @@ async function main(args) { '-open': util => util.alias('-open-playlist'), 'o': util => util.alias('-open-playlist'), + '-open-playlist-string': async function(util) { + // --open-playlist-string + // Opens a playlist, using the given string as the JSON text of the + // playlist. This sets the source playlist. + + await loadPlaylist(JSON.parse(util.nextArg())) + }, + '-write-playlist': function(util) { // --write-playlist (alias: --write, -w, --save) // Writes the active playlist to a file. This file can later be used diff --git a/todo.txt b/todo.txt index 32f000b..4250825 100644 --- a/todo.txt +++ b/todo.txt @@ -386,3 +386,14 @@ TODO: Should the '@ ...' part display the path to the track in the SOURCE active path is handy for debugging or writing your own playlist, but showing the source path is usually more practically useful, so you know where the album came from (e.g. displaying /C418/BAM instead of /BAM). + +TODO: Let playlists be passed to `play` by an actual string argument; e.g. + --playlist-string '{"tracks": [...]}'. Could work well with http-music's + own crawler utilities (e.g. --playlist-string + '{"source": ["crawl-local", "."]}' or with external ones (e.g. + --playlist-string "$(cool-crawler-utilith.sh)". At the moment the only + workaround is to use a temporary file to store the playlist in, or to + pipe the output of the crawler command (which might be `echo`!) to http- + music and use /dev/stdin as the --playlist-file value.. which obviously + isn't cross-platform or practical! + (Done!) -- cgit 1.3.0-6-gf8a5