diff options
-rw-r--r-- | man/http-music.1 | 15 | ||||
-rwxr-xr-x | src/http-music.js | 65 | ||||
-rw-r--r-- | todo.txt | 7 |
3 files changed, 69 insertions, 18 deletions
diff --git a/man/http-music.1 b/man/http-music.1 index fbc28c9..693cb4d 100644 --- a/man/http-music.1 +++ b/man/http-music.1 @@ -93,10 +93,10 @@ Forces the playlist not to play. See also \fB\-\-play\fR. .TP -.BR \-o ", " \-\-open " \fIplaylistFile\fR" +.BR \-o ", " \-\-open\-playlist ", " \-\-open " \fIplaylistFile\fR" Opens a specific file to be used as the playlist file. (This sets the source playlist.) -The default playlist file used upon loading is playlist.json (in the same directory as \fBhttp-music\fR is being run in). +The default playlist file used upon loading is \fBplaylist.json\fR (in the same directory as \fBhttp-music\fR is being run in). .TP .BR \-\-picker ", " \-\-selector " \fIpickerType\fR" @@ -110,15 +110,20 @@ Forces the playlist to actually play, regardless of options such as \fB\-\-list\ .TP .BR \-\-play\-opts Sets command line options passed to the \fBplay\fR command. -For example, playback volume may be set to 30% by using \fB\-\-play\-opts '\-v 0.3'\fR. +For example, playback volume may be set to 30% by using \fB\-\-play\-opts '\-\-volume 30'\fR. + +.TP +.BR \-\-print\-playlist ", " \-\-log-playlist ", " \-\-json +Prints the JSON representation of the active playlist to the console. .TP .BR \-r ", " \-\-remove ", " \-x " \fIgroupPath\fR" Removes a group from the (active) playlist. .TP -.BR \-\-debug\-list -Prints the JSON representation of the (active) playlist. +.BR \-w ", " \-\-write\-playlist ", " \-\-write ", " \-\-save " \fIfilePath\fR" +Writes the active playlist to a file. +This file can later be used with \fB\-\-open\fR; you won't need to stick in all the filtering options again. diff --git a/src/http-music.js b/src/http-music.js index a28b0f2..6457ef7 100755 --- a/src/http-music.js +++ b/src/http-music.js @@ -16,6 +16,7 @@ const { } = require('./playlist-utils') const readFile = promisify(fs.readFile) +const writeFile = promisify(fs.writeFile) function downloadPlaylistFromURL(url) { return fetch(url).then(res => res.text()) @@ -104,15 +105,64 @@ Promise.resolve() 'h': util => util.alias('-help'), '?': util => util.alias('-help'), - '-open': async function(util) { - // --open <file> (alias: -o) + '-open-playlist': async function(util) { + // --open-playlist <file> (alias: --open, -o) // Opens a separate playlist file. // This sets the source playlist. await openPlaylist(util.nextArg()) }, - 'o': util => util.alias('-open'), + '-open': util => util.alias('-open-playlist'), + 'o': util => util.alias('-open-playlist'), + + '-write-playlist': function(util) { + // --write-playlist <file> (alias: --write, -w, --save) + // Writes the active playlist to a file. This file can later be used + // with --open <file>; you won't need to stick in all the filtering + // options again. + + requiresOpenPlaylist() + + const playlistString = JSON.stringify(activePlaylist, null, 2) + const file = util.nextArg() + + console.log(`Saving playlist to file ${file}...`) + + return writeFile(file, playlistString).then(() => { + console.log("Saved.") + + // If this is the last option, the user probably doesn't actually + // want to play the playlist. (We need to check if this is len - 2 + // rather than len - 1, because of the <file> option that comes + // after --write-playlist.) + if (util.index === util.argv.length - 2) { + shouldPlay = false + } + }) + }, + + '-write': util => util.alias('-write-playlist'), + 'w': util => util.alias('-write-playlist'), + '-save': util => util.alias('-write-playlist'), + + '-print-playlist': function(util) { + // --print-playlist (alias: --log-playlist, --json) + // Prints out the JSON representation of the active playlist. + + requiresOpenPlaylist() + + console.log(JSON.stringify(activePlaylist, null, 2)) + + // As with --write-playlist, the user probably doesn't want to actually + // play anything if this is the last option. + if (util.index === util.argv.length - 1) { + shouldPlay = false + } + }, + + '-log-playlist': util => util.alias('-print-playlist'), + '-json': util => util.alias('-print-playlist'), '-clear': function(util) { // --clear (alias: -c) @@ -226,15 +276,6 @@ Promise.resolve() // Sets command line options passed to the `play` command. playOpts = util.nextArg().split(' ') - }, - - '-debug-list': function(util) { - // --debug-list - // Prints out the JSON representation of the active playlist. - - requiresOpenPlaylist() - - console.log(JSON.stringify(activePlaylist, null, 2)) } } diff --git a/todo.txt b/todo.txt index 6115430..6d4da81 100644 --- a/todo.txt +++ b/todo.txt @@ -97,6 +97,7 @@ TODO: Make a --help/-h/-? option that directs helpless users to the man page. TODO: Make a way to write the current playlist to a file. I think just renaming the debug-playlist-log option could work, since you could pipe that to a file through your shell. + (Done!) TODO: Figure out a less "hacky" way to kill the process. Ideally we shouldn't have to handle ^C and ^D ourselves; for instance right now ^Z is actually @@ -207,5 +208,9 @@ TODO: Tracks should be able to contain more data than the title and downloader TODO: Piping the output of a crawl command into the http-music command would be nifty! -TODO: Having all the HTTP-music commands be stuck into one main command might +TODO: Having all the http-music commands be stuck into one main command might be nice, like the way git does it.. + +TODO: Figure out how man pages work, and update the syntax in those files. + Particularly I'd like to make the number of blank lines between headings + more consistent, and figure out when to use '\-' or '-'. |