« get me outta code hell

Move redundant things into processSmartPlaylist - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-03-19 23:03:00 -0300
committerFlorrie <towerofnix@gmail.com>2018-03-19 23:03:00 -0300
commitbf0a68349b69fb5b8bd50b7e38ad6a88540e431a (patch)
treec5e5e818414110f8e042b63397fc6b953f0b2bda
parentbf69e4afd6515954128f5d9129396c56553005e3 (diff)
Move redundant things into processSmartPlaylist
-rw-r--r--src/general-util.js18
-rw-r--r--src/process-metadata.js3
-rw-r--r--src/smart-playlist.js8
3 files changed, 13 insertions, 16 deletions
diff --git a/src/general-util.js b/src/general-util.js
index 278eea6..b37f516 100644
--- a/src/general-util.js
+++ b/src/general-util.js
@@ -100,25 +100,17 @@ module.exports.makePlaylistOptions = function() {
     // 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)
-
-    // ..And finally, we have to update the playlist format again, since
-    // processSmartPlaylist might have added new (un-updated) items:
-    const finalPlaylist = updatePlaylistFormat(processedPlaylist, true)
-    // We also pass true so that the playlist-format-updater knows that this
-    // is the source playlist.
-
-    sourcePlaylist = finalPlaylist
+    // We want to de-smart-ify (stupidify? - simplify?) the playlist.
+    // This also automatically updates the playlist format for us, which is
+    // handy.
+    sourcePlaylist = await processSmartPlaylist(importedPlaylist)
 
     // 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.
     activePlaylist = clone(sourcePlaylist)
 
-    await processArgv(processedPlaylist.options, optionFunctions)
+    await processArgv(sourcePlaylist.options, optionFunctions)
   }
 
   const requiresOpenPlaylist = async function() {
diff --git a/src/process-metadata.js b/src/process-metadata.js
index 43ffe62..903a73c 100644
--- a/src/process-metadata.js
+++ b/src/process-metadata.js
@@ -5,6 +5,7 @@ const { spawn } = require('child_process')
 const { promisify } = require('util')
 const { showTrackProcessStatus } = require('./general-util')
 const { updatePlaylistFormat, flattenGrouplike } = require('./playlist-utils')
+const { processSmartPlaylist } = require('./smart-playlist')
 
 const readFile = promisify(fs.readFile)
 const writeFile = promisify(fs.writeFile)
@@ -72,7 +73,7 @@ async function main(args) {
 
   let doneCount = 0
 
-  const playlist = updatePlaylistFormat(JSON.parse(await readFile(args[0])))
+  const playlist = await processSmartPlaylist(JSON.parse(await readFile(args[0])))
 
   const flattened = flattenGrouplike(playlist)
   for (const item of flattened.items) {
diff --git a/src/smart-playlist.js b/src/smart-playlist.js
index cbe5182..395c590 100644
--- a/src/smart-playlist.js
+++ b/src/smart-playlist.js
@@ -2,7 +2,7 @@
 
 const fs = require('fs')
 const { getCrawlerByName } = require('./crawlers')
-const { isGroup, filterTracks, sourceSymbol } = require('./playlist-utils')
+const { isGroup, filterTracks, sourceSymbol, updatePlaylistFormat } = require('./playlist-utils')
 
 const { promisify } = require('util')
 const readFile = promisify(fs.readFile)
@@ -11,6 +11,8 @@ async function processSmartPlaylist(item) {
   // Object.assign is used so that we keep original properties, e.g. "name"
   // or "apply". (It's also used so we return copies of original objects.)
 
+  item = await updatePlaylistFormat(item)
+
   const newItem = Object.assign({}, item)
 
   if ('source' in newItem) {
@@ -120,7 +122,9 @@ async function processSmartPlaylist(item) {
     delete newItem.filters
   }
 
-  return newItem
+  // We pass true so that the playlist-format-updater knows that this
+  // is going to be the source playlist, probably.
+  return updatePlaylistFormat(newItem, true)
 }
 
 async function main(opts) {