From 6e704c4531c7396ca595d03a6814b823430570bb Mon Sep 17 00:00:00 2001 From: vapormusic Date: Mon, 10 Jan 2022 09:50:11 +0700 Subject: [PATCH] fix queueing --- src/renderer/assets/repeat.svg | 28 ++--- src/renderer/index.js | 29 +++-- src/renderer/style.less | 4 + .../views/components/mediaitem-list-item.ejs | 110 ++++++++---------- src/renderer/views/pages/cider-playlist.ejs | 42 +++---- 5 files changed, 99 insertions(+), 114 deletions(-) diff --git a/src/renderer/assets/repeat.svg b/src/renderer/assets/repeat.svg index 0c283cf4..752848dd 100644 --- a/src/renderer/assets/repeat.svg +++ b/src/renderer/assets/repeat.svg @@ -1,18 +1,20 @@ - - - + + - - + + + + + + diff --git a/src/renderer/index.js b/src/renderer/index.js index 39144597..bdff4a06 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -2375,22 +2375,21 @@ const app = new Vue({ } else { app.mk.stop().then(() => { if (truekind == "playlists" && (id.startsWith("p.") || id.startsWith("pl.u"))){ - app.mk.playNext({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () { - app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ?? 1) - app.mk.play().then(function(){ - app.mk.clearQueue().then(function () { - if ((app.showingPlaylist && app.showingPlaylist.id == id)) { + app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () { + app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ?? 1).then(function(){ + if ((app.showingPlaylist && app.showingPlaylist.id == id)) { + let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); + if (query.length > 100) { + let u = query.slice(100); if (app.mk.shuffleMode == 1) { shuffleArray(u) } + app.mk.queue.append(u)} + } else { + app.getPlaylistFromID(id, true).then(function () { let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); - if (app.mk.shuffleMode == 1){ shuffleArray(query)} - app.mk.queue.append(query) - } else { - app.getPlaylistFromID(id, true).then(function () { - let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); - if (app.mk.shuffleMode == 1){ shuffleArray(query)} - app.mk.queue.append(query) - }) - } - }) + if (query.length > 100) { + let u = query.slice(100); if (app.mk.shuffleMode == 1) { shuffleArray(u) } + app.mk.queue.append(u)} + }) + } }) }) diff --git a/src/renderer/style.less b/src/renderer/style.less index 078e0a62..bebf8bad 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3578,6 +3578,10 @@ input[type="range"].web-slider.display--small::-webkit-slider-thumb { background-color: rgba(200, 200, 200, 0.7); } + .playback-button--small{ + opacity: 0.7; + } + .right-col{ height: 50vh; } diff --git a/src/renderer/views/components/mediaitem-list-item.ejs b/src/renderer/views/components/mediaitem-list-item.ejs index 409763bb..bd6f27fb 100644 --- a/src/renderer/views/components/mediaitem-list-item.ejs +++ b/src/renderer/views/components/mediaitem-list-item.ejs @@ -416,73 +416,61 @@ if (parent != null && childIndex != null) { app.queueParentandplayChild(parent, childIndex, item); } - // else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl."))){ - // function shuffleArray(array) { - // for (var i = array.length - 1; i > 0; i--) { - // var j = Math.floor(Math.random() * (i + 1)); - // var temp = array[i]; - // array[i] = array[j]; - // array[j] = temp; - // } - // } - // app.mk.clearQueue().then(function () { - // app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () { - // app.mk.play().then(function (){ - // app.mk.clearQueue().then(function (){ - // var playlistId = id - // const params = { - // // include: "tracks", - // // platform: "web", - // // "include[library-playlists]": "catalog,tracks", - // // "fields[playlists]": "curatorName,playlistType,name,artwork,url", - // // "include[library-songs]": "catalog,artists,albums", - // // "fields[catalog]": "artistUrl,albumUrl", - // // "fields[songs]": "artistUrl,albumUrl, playParams" - // } - // // var playlistId = '' - // function getPlaylist(id, params, isLibrary){ - // if (isLibrary){ - // return app.mk.api.library.playlist(id, params) - // } else { return app.mk.api.playlist(id, params)} - // } - // try { + else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl."))){ + function shuffleArray(array) { + for (var i = array.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + } + app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () { + app.mk.play().then(function (){ + var playlistId = id + function getPlaylist(id, params, isLibrary){ + if (isLibrary){ + return app.mk.api.library.playlist(id, params) + } else { return app.mk.api.playlist(id, params)} + } + try { - // getPlaylist(id, params, isLibrary).then(res => { - // let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); - // if (app.mk.shuffleMode == 1){shuffleArray(query); } - // console.log(query) - // app.mk.queue.append(query) - // if (!res.relationships.tracks.next) { - // return - // } else { - // getPlaylistTracks(res.relationships.tracks.next) - // } + getPlaylist(id, params, isLibrary).then(res => { + //let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); + //if (app.mk.shuffleMode == 1){shuffleArray(query); } + // console.log(query) + // app.mk.queue.append(query) + if (!res.relationships.tracks.next) { + return + } else { + getPlaylistTracks(res.relationships.tracks.next) + } - // function getPlaylistTracks(next) { - // app.apiCall(app.musicBaseUrl + next, res => { - // // if (res.id != playlistId || next.includes(playlistId)) { - // // return - // // } - // console.log('nextres', res) - // let query = res.data.map(item => new MusicKit.MediaItem(item)) - // if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')} - // app.mk.queue.append(query) + function getPlaylistTracks(next) { + app.apiCall(app.musicBaseUrl + next, res => { + // if (res.id != playlistId || next.includes(playlistId)) { + // return + // } + console.log('nextres', res) + let query = res.data.map(item => new MusicKit.MediaItem(item)) + if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')} + app.mk.queue.append(query) - // if (res.next) { - // getPlaylistTracks(res.next) - // } - // }) - // } - // }) - // } catch (e) {} + if (res.next) { + getPlaylistTracks(res.next) + } + }) + } + }) + } catch (e) {} - // }) - // }) - // }) + + }) + }) - // }) - // } + + } else { app.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url) }}) diff --git a/src/renderer/views/pages/cider-playlist.ejs b/src/renderer/views/pages/cider-playlist.ejs index 0250a153..de987fc3 100644 --- a/src/renderer/views/pages/cider-playlist.ejs +++ b/src/renderer/views/pages/cider-playlist.ejs @@ -59,11 +59,11 @@