« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/smart-playlist.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/smart-playlist.js')
-rw-r--r--src/smart-playlist.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/smart-playlist.js b/src/smart-playlist.js
index 395c590..7c09919 100644
--- a/src/smart-playlist.js
+++ b/src/smart-playlist.js
@@ -7,11 +7,13 @@ const { isGroup, filterTracks, sourceSymbol, updatePlaylistFormat } = require('.
 const { promisify } = require('util')
 const readFile = promisify(fs.readFile)
 
-async function processSmartPlaylist(item) {
+async function processSmartPlaylist(item, topItem = true) {
   // 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)
+  if (topItem) {
+    item = await updatePlaylistFormat(item)
+  }
 
   const newItem = Object.assign({}, item)
 
@@ -30,7 +32,9 @@ async function processSmartPlaylist(item) {
 
     delete newItem.source
   } else if ('items' in newItem) {
-    newItem.items = await Promise.all(item.items.map(processSmartPlaylist))
+    // Pass topItem = false, since we don't want to use updatePlaylistFormat
+    // on these items.
+    newItem.items = await Promise.all(item.items.map(x => processSmartPlaylist(x, false)))
   }
 
   if ('filters' in newItem) filters: {
@@ -122,9 +126,13 @@ async function processSmartPlaylist(item) {
     delete newItem.filters
   }
 
-  // We pass true so that the playlist-format-updater knows that this
-  // is going to be the source playlist, probably.
-  return updatePlaylistFormat(newItem, true)
+  if (topItem) {
+    // We pass true so that the playlist-format-updater knows that this
+    // is going to be the source playlist, probably.
+    return updatePlaylistFormat(newItem, true)
+  } else {
+    return newItem
+  }
 }
 
 async function main(opts) {