diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/play.js | 10 | ||||
-rw-r--r-- | src/smart-playlist.js | 20 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/play.js b/src/play.js index b2c04e9..7807c93 100755 --- a/src/play.js +++ b/src/play.js @@ -10,6 +10,7 @@ const npmCommandExists = require('command-exists') const pickers = require('./pickers') const loopPlay = require('./loop-play') const processArgv = require('./process-argv') +const processSmartPlaylist = require('./smart-playlist') const { filterPlaylistByPathString, removeGroupByPathString, getPlaylistTreeString, @@ -95,13 +96,16 @@ async function main(args) { const openedPlaylist = updatePlaylistFormat(JSON.parse(playlistText)) + // We also want to de-smart-ify (stupidify? - simplify?) the playlist. + const processedPlaylist = await processSmartPlaylist(openedPlaylist) + // The active playlist is a clone of the source playlist; after all it's // quite possible we'll be messing with the value of the active playlist, // and we don't want to reflect those changes in the source playlist. - sourcePlaylist = openedPlaylist - activePlaylist = clone(openedPlaylist) + sourcePlaylist = processedPlaylist + activePlaylist = clone(processedPlaylist) - processArgv(openedPlaylist.options, optionFunctions) + processArgv(processedPlaylist.options, optionFunctions) } function requiresOpenPlaylist() { diff --git a/src/smart-playlist.js b/src/smart-playlist.js index e65ff1f..76cd877 100644 --- a/src/smart-playlist.js +++ b/src/smart-playlist.js @@ -8,30 +8,32 @@ const readFile = promisify(fs.readFile) async function processItem(item) { // Object.assign is used so that we keep original properties, e.g. "name" - // or "apply". + // or "apply". (It's also used so we return copies of original objects.) - if ('items' in item) { - return Object.assign(item, { - items: await Promise.all(item.items.map(processItem)) - }) - } else if ('source' in item) { + if ('source' in item) { const [ name, ...args ] = item.source const crawlModule = getCrawlerByName(name) if (crawlModule === null) { console.error(`No crawler by name ${name} - skipped item:`, item) - return Object.assign(item, {failed: true}) + return Object.assign({}, item, {failed: true}) } const { crawl } = crawlModule - return Object.assign(item, await crawl(...args)) + return Object.assign({}, item, await crawl(...args)) + } else if ('items' in item) { + return Object.assign({}, item, { + items: await Promise.all(item.items.map(processItem)) + }) } else { - return item + return Object.assign({}, item) } } +module.exports = processItem + async function main(opts) { // TODO: Error when no file is given |