From a10e44d9461adaaf72ac1f6fe51b4efa5f07b244 Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 26 Jun 2017 13:16:33 -0300 Subject: Store options in playlists (e.g. --downloader local) --- src/http-music.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/http-music.js b/src/http-music.js index 494ec17..6abda75 100755 --- a/src/http-music.js +++ b/src/http-music.js @@ -48,8 +48,41 @@ Promise.resolve() } const openedPlaylist = JSON.parse(playlistText) - sourcePlaylist = openedPlaylist - activePlaylist = openedPlaylist + + // Playlists can be in two formats... + if (Array.isArray(openedPlaylist)) { + // ..the first, a simple array of tracks and groups; + + sourcePlaylist = openedPlaylist + activePlaylist = openedPlaylist + } else if (typeof openedPlaylist === 'object') { + // ..or an object including metadata and configuration as well as the + // array described in the first. + + if (!('tracks' in openedPlaylist)) { + throw new Error( + "Trackless object-type playlist (requires 'tracks' property)" + ) + } + + sourcePlaylist = openedPlaylist.tracks + activePlaylist = openedPlaylist.tracks + + // What's handy about the object-type playlist is that you can pass + // options that will be run every time the playlist is opened: + if ('options' in openedPlaylist) { + if (Array.isArray(openedPlaylist.options)) { + processArgv(openedPlaylist.options, optionFunctions) + } else { + throw new Error( + "Invalid 'options' property (expected array): " + file + ) + } + } + } else { + // Otherwise something's gone horribly wrong..! + throw new Error("Invalid playlist file contents: " + file) + } } function requiresOpenPlaylist() { -- cgit 1.3.0-6-gf8a5