add fix for bulk artist requests, over develop
This commit is contained in:
parent
ef249519e7
commit
0135d73556
2 changed files with 31 additions and 16 deletions
|
@ -78,21 +78,30 @@
|
||||||
let self = this
|
let self = this
|
||||||
this.artists = []
|
this.artists = []
|
||||||
this.artistFeed = []
|
this.artistFeed = []
|
||||||
this.app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists?ids=${artists.toString()}&views=latest-release&include[songs]=albums&fields[albums]=artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount&limit[artists:top-songs]=2&art[url]=f`,{ l : this.$root.mklang}).then(artistData => {
|
|
||||||
artistData.data.data.forEach(item => {
|
// Apple limits the number of IDs we can provide in a single API call to 50.
|
||||||
|
// Divide it into groups of 50 and send parallel requests
|
||||||
|
let chunks = []
|
||||||
|
for (let artistIdx = 0; artistIdx < artists.length; artistIdx += 50) {
|
||||||
|
chunks.push(artists.slice(artistIdx, artistIdx + 50))
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const chunkArtistData = await Promise.all(chunks.map(chunk =>
|
||||||
|
this.app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists?ids=${chunk.toString()}&views=latest-release&include[songs]=albums&fields[albums]=artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount&limit[artists:top-songs]=2&art[url]=f`)))
|
||||||
|
chunkArtistData.forEach(chunkResult =>
|
||||||
|
chunkResult.data.data.forEach(item => {
|
||||||
self.artists.push(item)
|
self.artists.push(item)
|
||||||
if (item.views["latest-release"].data.length != 0) {
|
if (item.views["latest-release"].data.length != 0) {
|
||||||
self.artistFeed.push(item.views["latest-release"].data[0])
|
self.artistFeed.push(item.views["latest-release"].data[0])
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
// sort artistFeed by attributes.releaseDate descending, date is formatted as "YYYY-MM-DD"
|
// sort artistFeed by attributes.releaseDate descending, date is formatted as "YYYY-MM-DD"
|
||||||
this.artistFeed.sort((a, b) => {
|
this.artistFeed.sort((a, b) => {
|
||||||
let dateA = new Date(a.attributes.releaseDate)
|
let dateA = new Date(a.attributes.releaseDate)
|
||||||
let dateB = new Date(b.attributes.releaseDate)
|
let dateB = new Date(b.attributes.releaseDate)
|
||||||
return dateB - dateA
|
return dateB - dateA
|
||||||
})
|
})
|
||||||
})
|
} catch (err) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -177,21 +177,27 @@
|
||||||
async getArtistFeed() {
|
async getArtistFeed() {
|
||||||
let artists = this.followedArtists
|
let artists = this.followedArtists
|
||||||
let self = this
|
let self = this
|
||||||
this.app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists?ids=${artists.toString()}&views=latest-release&include[songs]=albums&fields[albums]=artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount&limit[artists:top-songs]=2&art[url]=f&l=${this.$root.mklang}`).then(artistData => {
|
|
||||||
artistData.data.data.forEach(item => {
|
let chunks = []
|
||||||
|
for (let artistIdx = 0; artistIdx < artists.length; artistIdx += 50) {
|
||||||
|
chunks.push(artists.slice(artistIdx, artistIdx + 50));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const chunkArtistData = await Promise.all(chunks.map(chunk =>
|
||||||
|
this.app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists?ids=${chunk.toString()}&views=latest-release&include[songs]=albums&fields[albums]=artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount&limit[artists:top-songs]=2&art[url]=f`)))
|
||||||
|
chunkArtistData.forEach(chunkResult =>
|
||||||
|
chunkResult.data.data.forEach(item => {
|
||||||
if (item.views["latest-release"].data.length != 0) {
|
if (item.views["latest-release"].data.length != 0) {
|
||||||
self.artistFeed.push(item.views["latest-release"].data[0])
|
self.artistFeed.push(item.views["latest-release"].data[0])
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
// sort artistFeed by attributes.releaseDate descending, date is formatted as "YYYY-MM-DD"
|
// sort artistFeed by attributes.releaseDate descending, date is formatted as "YYYY-MM-DD"
|
||||||
this.artistFeed.sort((a, b) => {
|
this.artistFeed.sort((a, b) => {
|
||||||
let dateA = new Date(a.attributes.releaseDate)
|
let dateA = new Date(a.attributes.releaseDate)
|
||||||
let dateB = new Date(b.attributes.releaseDate)
|
let dateB = new Date(b.attributes.releaseDate)
|
||||||
return dateB - dateA
|
return dateB - dateA
|
||||||
})
|
})
|
||||||
})
|
} catch (error) { }
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
getRecentlyPlayed() {
|
getRecentlyPlayed() {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue