« get me outta code hell

Make group-shuffle actually work - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-08-11 10:31:13 -0300
committerFlorrie <towerofnix@gmail.com>2017-08-11 10:31:13 -0300
commit2a15db9095ab0494c0cbaec9fbbf1fe11146306b (patch)
treec35be53f62234d99dddb86bb8f68a019f1aec902 /src
parent490d584a9a393a29cac08fc28223b0a7b6f802dc (diff)
Make group-shuffle actually work
Diffstat (limited to 'src')
-rw-r--r--src/pickers.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pickers.js b/src/pickers.js
index 6a30c37..2d8c631 100644
--- a/src/pickers.js
+++ b/src/pickers.js
@@ -1,6 +1,15 @@
 'use strict'
 
-const { flattenGrouplike } = require('./playlist-utils')
+const { flattenGrouplike, isGroup } = require('./playlist-utils')
+
+function shuffleGroups(grouplike) {
+  if (isGroup(grouplike) && grouplike.items.every(isGroup)) {
+    const items = shuffleArray(grouplike.items.map(shuffleGroups))
+    return Object.assign({}, grouplike, {items})
+  } else {
+    return grouplike
+  }
+}
 
 function makePicker(grouplike, sort, loop) {
   // Options to take into consideration:
@@ -31,7 +40,8 @@ function makePicker(grouplike, sort, loop) {
     }
 
     if (sort === 'shuffle-top-level' || sort === 'shuffle-groups') {
-      topLevel.items = flattenGrouplike(shuffleArray(grouplike.items))
+      console.log(JSON.stringify(shuffleGroups(grouplike), null, 2))
+      topLevel.items = flattenGrouplike(shuffleGroups(grouplike)).items
     }
 
     console.log(topLevel.items.map(require('./playlist-utils').getItemPathString).join('\n'))