some queue fix
This commit is contained in:
parent
0aa402b6aa
commit
b638a2c877
3 changed files with 103 additions and 24 deletions
|
@ -1194,7 +1194,7 @@ const app = new Vue({
|
||||||
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
|
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
|
||||||
;
|
;
|
||||||
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
console.log(kind, id, isLibrary)
|
console.log(kind, id, isLibrary)
|
||||||
app.mk.stop().then(() => {
|
app.mk.stop().then(() => {
|
||||||
if (kind.includes("artist")) {
|
if (kind.includes("artist")) {
|
||||||
|
@ -1212,7 +1212,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.mk.clearQueue().then(function () { {
|
app.mk.clearQueue().then(function () { {
|
||||||
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () {
|
||||||
app.mk.play().then(function (){
|
app.mk.play().then(function (){
|
||||||
app.mk.clearQueue().then(function (){
|
app.mk.clearQueue().then(function (){
|
||||||
var playlistId = id
|
var playlistId = id
|
||||||
|
|
|
@ -410,12 +410,12 @@
|
||||||
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ?? (item.type ?? '')) : (item.type ?? ''));
|
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ?? (item.type ?? '')) : (item.type ?? ''));
|
||||||
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));;
|
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));;
|
||||||
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
console.log(item, parent, childIndex, kind, id, isLibrary, kind == "playlists", id.startsWith("p.") || id.startsWith("pl.u"))
|
console.log(item, parent, childIndex, kind, id, isLibrary, kind == "playlists", id.startsWith("p.") || id.startsWith("pl.u"))
|
||||||
app.mk.stop().then(() => {
|
app.mk.stop().then(() => {
|
||||||
if (parent != null && childIndex != null) {
|
if (parent != null && childIndex != null) {
|
||||||
app.queueParentandplayChild(parent, childIndex, item);
|
app.queueParentandplayChild(parent, childIndex, item);
|
||||||
} else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl."))){
|
} else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl."))){
|
||||||
/* Randomize array in-place using Durstenfeld shuffle algorithm */
|
|
||||||
function shuffleArray(array) {
|
function shuffleArray(array) {
|
||||||
for (var i = array.length - 1; i > 0; i--) {
|
for (var i = array.length - 1; i > 0; i--) {
|
||||||
var j = Math.floor(Math.random() * (i + 1));
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
@ -425,20 +425,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.mk.clearQueue().then(function () {
|
app.mk.clearQueue().then(function () {
|
||||||
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () {
|
||||||
app.mk.play().then(function (){
|
app.mk.play().then(function (){
|
||||||
app.mk.clearQueue().then(function (){
|
app.mk.clearQueue().then(function (){
|
||||||
var playlistId = id
|
var playlistId = id
|
||||||
const params = {
|
const params = {
|
||||||
include: "tracks",
|
// include: "tracks",
|
||||||
platform: "web",
|
// platform: "web",
|
||||||
"include[library-playlists]": "catalog,tracks",
|
// "include[library-playlists]": "catalog,tracks",
|
||||||
"fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
// "fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
||||||
"include[library-songs]": "catalog,artists,albums",
|
// "include[library-songs]": "catalog,artists,albums",
|
||||||
"fields[catalog]": "artistUrl,albumUrl",
|
// "fields[catalog]": "artistUrl,albumUrl",
|
||||||
"fields[songs]": "artistUrl,albumUrl"
|
// "fields[songs]": "artistUrl,albumUrl, playParams"
|
||||||
}
|
}
|
||||||
var playlistId = ''
|
// var playlistId = ''
|
||||||
function getPlaylist(id, params, isLibrary){
|
function getPlaylist(id, params, isLibrary){
|
||||||
if (isLibrary){
|
if (isLibrary){
|
||||||
return app.mk.api.library.playlist(id, params)
|
return app.mk.api.library.playlist(id, params)
|
||||||
|
@ -448,7 +448,8 @@
|
||||||
|
|
||||||
getPlaylist(id, params, isLibrary).then(res => {
|
getPlaylist(id, params, isLibrary).then(res => {
|
||||||
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
if (app.mk.shuffleMode == 1){shuffleArray(query); }
|
||||||
|
console.log(query)
|
||||||
app.mk.queue.append(query)
|
app.mk.queue.append(query)
|
||||||
if (!res.relationships.tracks.next) {
|
if (!res.relationships.tracks.next) {
|
||||||
return
|
return
|
||||||
|
@ -458,9 +459,10 @@
|
||||||
|
|
||||||
function getPlaylistTracks(next) {
|
function getPlaylistTracks(next) {
|
||||||
app.apiCall(app.musicBaseUrl + next, res => {
|
app.apiCall(app.musicBaseUrl + next, res => {
|
||||||
if (res.id != playlistId) {
|
// if (res.id != playlistId || next.includes(playlistId)) {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
console.log('nextres', res)
|
||||||
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
||||||
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
app.mk.queue.append(query)
|
app.mk.queue.append(query)
|
||||||
|
|
|
@ -59,11 +59,11 @@
|
||||||
</template>
|
</template>
|
||||||
<div class="playlist-controls">
|
<div class="playlist-controls">
|
||||||
<button class="wr-btn" style="min-width: 120px;"
|
<button class="wr-btn" style="min-width: 120px;"
|
||||||
@click="app.mk.shuffleMode = 0;app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)">
|
@click="app.mk.shuffleMode = 0; app.mk.stop().then(function() {app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)})">
|
||||||
Play
|
Play
|
||||||
</button>
|
</button>
|
||||||
<button class="wr-btn" style="min-width: 120px;"
|
<button class="wr-btn" style="min-width: 120px;"
|
||||||
@click="app.mk.shuffleMode = 1;app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)">
|
@click="shufflePlay()">
|
||||||
Shuffle
|
Shuffle
|
||||||
</button>
|
</button>
|
||||||
<button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null"
|
<button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null"
|
||||||
|
@ -152,7 +152,7 @@
|
||||||
}
|
}
|
||||||
this.$root.getSocialBadges((badges) => {
|
this.$root.getSocialBadges((badges) => {
|
||||||
let friends = badges[id]
|
let friends = badges[id]
|
||||||
if(friends) {
|
if (friends) {
|
||||||
friends.forEach(function (friend) {
|
friends.forEach(function (friend) {
|
||||||
self.app.mk.api.socialProfile(friend).then(data => {
|
self.app.mk.api.socialProfile(friend).then(data => {
|
||||||
self.itemBadges.push(data)
|
self.itemBadges.push(data)
|
||||||
|
@ -192,7 +192,7 @@
|
||||||
async isInLibrary() {
|
async isInLibrary() {
|
||||||
if (this.data.type && !this.data.type.includes("library")) {
|
if (this.data.type && !this.data.type.includes("library")) {
|
||||||
// please keep using vars here
|
// please keep using vars here
|
||||||
var params = {"fields[playlists]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library"}
|
var params = { "fields[playlists]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library" }
|
||||||
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false, this.data.attributes.playParams.id ?? this.data.id, params);
|
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false, this.data.attributes.playParams.id ?? this.data.id, params);
|
||||||
this.inLibrary = (res && res.attributes && res.attributes.inLibrary) ? res.attributes.inLibrary : false
|
this.inLibrary = (res && res.attributes && res.attributes.inLibrary) ? res.attributes.inLibrary : false
|
||||||
console.log(res)
|
console.log(res)
|
||||||
|
@ -214,7 +214,7 @@
|
||||||
this.inLibrary = true
|
this.inLibrary = true
|
||||||
},
|
},
|
||||||
async removeFromLibrary(id) {
|
async removeFromLibrary(id) {
|
||||||
var params = {"fields[somgs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library"}
|
var params = { "fields[somgs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library" }
|
||||||
var id = this.data.id ?? this.data.attributes.playParams.id
|
var id = this.data.id ?? this.data.attributes.playParams.id
|
||||||
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false, this.data.attributes.playParams.id ?? this.data.id, params);
|
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false, this.data.attributes.playParams.id ?? this.data.id, params);
|
||||||
if (res && res.relationships && res.relationships.library && res.relationships.library.data && res.relationships.library.data.length > 0) {
|
if (res && res.relationships && res.relationships.library && res.relationships.library.data && res.relationships.library.data.length > 0) {
|
||||||
|
@ -222,7 +222,7 @@
|
||||||
}
|
}
|
||||||
let kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
|
let kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
|
||||||
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
app.mk.api.library.remove({[truekind]: id})
|
app.mk.api.library.remove({ [truekind]: id })
|
||||||
this.inLibrary = false
|
this.inLibrary = false
|
||||||
},
|
},
|
||||||
editPlaylistName() {
|
editPlaylistName() {
|
||||||
|
@ -304,7 +304,7 @@
|
||||||
if (date == null || date === "") return "";
|
if (date == null || date === "") return "";
|
||||||
try {
|
try {
|
||||||
var releaseDate = new Date(date);
|
var releaseDate = new Date(date);
|
||||||
month = new Intl.DateTimeFormat('en-US', {month: 'long'}).format(releaseDate);
|
month = new Intl.DateTimeFormat('en-US', { month: 'long' }).format(releaseDate);
|
||||||
date = releaseDate.getDate();
|
date = releaseDate.getDate();
|
||||||
year = releaseDate.getFullYear();
|
year = releaseDate.getFullYear();
|
||||||
|
|
||||||
|
@ -312,7 +312,84 @@
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
shufflePlay() {
|
||||||
|
app.mk.shuffleMode = 1;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var id = this.data.attributes.playParams.id ?? this.data.id
|
||||||
|
let kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
|
let isLibrary = this.data.attributes.playParams ? (this.data.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
app.mk.stop().then(function() {
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
app.mk.setQueue({ [truekind] : [id] }).then(function () {
|
||||||
|
app.mk.play().then(function () {
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
function getList(kind, id, params, isLibrary) {
|
||||||
|
if (kind.includes("album")){
|
||||||
|
if (isLibrary) {
|
||||||
|
return app.mk.api.library.album(id, params)
|
||||||
|
} else { return app.mk.api.album(id, params) }
|
||||||
|
} else {
|
||||||
|
if (isLibrary) {
|
||||||
|
return app.mk.api.library.playlist(id, params)
|
||||||
|
} else { return app.mk.api.playlist(id, params) }}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
|
||||||
|
getPlaylist(kind, id, params, isLibrary).then(res => {
|
||||||
|
console.log(res)
|
||||||
|
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
|
if (app.mk.shuffleMode == 1) { shuffleArray(query); console.log('shf') }
|
||||||
|
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) {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
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) {console.log(e) }
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})}
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue