From 802436e875f35fcb3c25d57af018f8f2eec03e62 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sat, 12 Feb 2022 23:24:00 +0700 Subject: [PATCH] top songs queuing (listitem-horizontal) --- src/renderer/index.js | 62 ++++++++++++++++++- .../views/components/listitem-horizontal.ejs | 11 +++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/renderer/index.js b/src/renderer/index.js index f4d1aaa4..e6c2814e 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -2814,7 +2814,67 @@ const app = new Vue({ }) } }) - } else { + } else if (parent.startsWith('listitem-hr')) { + app.mk.stop().then(() => { + if (app.mk.shuffleMode == 1) { + app.mk.setQueue({ + [item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id + }).then(function () { + app.mk.play().then(() => { + const data = JSON.parse(parent.split('listitem-hr')[1] ?? '[]') + let itemsToPlay = {} + let u = data.map(x => x.id) + try { + data.splice(u.indexOf(item.attributes.playParams.id ?? item.id), 1) + } catch (e) { } + if (app.mk.shuffleMode == 1) { + shuffleArray(data) + } + data.forEach(item => { + if (!itemsToPlay[item.kind]) { + itemsToPlay[item.kind] = [] + } + itemsToPlay[item.kind].push(item.id) + }) + // loop through itemsToPlay + for (let kind in itemsToPlay) { + let ids = itemsToPlay[kind] + if (ids.length > 0) { + app.mk.playLater({ [kind + "s"]: itemsToPlay[kind] }) + } + } + }) + }) + } else { + const data = JSON.parse(parent.split('listitem-hr')[1] ?? '[]') + let itemsToPlay = {} + let u = data.map(x => x.id) + data.forEach(item => { + if (!itemsToPlay[item.kind]) { + itemsToPlay[item.kind] = [] + } + itemsToPlay[item.kind].push(item.id) + }) + // loop through itemsToPlay + let ind = 0; + for (let kind in itemsToPlay) { + let ids = itemsToPlay[kind] + app.mk.clearQueue().then(function () { + if (ids.length > 0) { + app.mk.playLater({ [kind + "s"]: itemsToPlay[kind] }).then(function() { + ind += 1; + console.log(ind , Object.keys(itemsToPlay).length) + if(ind >= Object.keys(itemsToPlay).length) { + app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id)) + } + } + )} + }) + } + } + }) + } + else { app.mk.stop().then(() => { if (truekind == "playlists" && (id.startsWith("p.") || id.startsWith("pl.u"))) { app.mk.setQueue({ diff --git a/src/renderer/views/components/listitem-horizontal.ejs b/src/renderer/views/components/listitem-horizontal.ejs index 73d74838..a159f362 100644 --- a/src/renderer/views/components/listitem-horizontal.ejs +++ b/src/renderer/views/components/listitem-horizontal.ejs @@ -3,7 +3,7 @@
@@ -23,7 +23,8 @@ }, data: function () { return { - itemPages: [] + itemPages: [], + simplifiedParent : [] } }, mounted() { @@ -33,6 +34,12 @@ }); // split items into pages this.itemPages = app.arrayToChunk(this.items, 4); + try{ + this.simplifiedParent = JSON.stringify(this.items.map ( function(x){return x.attributes.playParams})); + console.log("simplifiedParent: " + this.simplifiedParent); + } + catch (e){} + }, methods: { sayHello: function () {