Skip to content

Commit

Permalink
Get all tracks in playlist instead of only first 100.
Browse files Browse the repository at this point in the history
  • Loading branch information
RuurdBijlsma committed Nov 6, 2024
1 parent 109de6f commit 6473774
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ruurd-music",
"version": "6.11.0",
"version": "6.11.1",
"description": "A streaming music player",
"main": "./out/main/index.js",
"keywords": [
Expand Down
20 changes: 16 additions & 4 deletions src/renderer/src/store/spotify-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,22 @@ export const useSpotifyApiStore = defineStore('spotify-api', () => {
}

const getPlaylist = async (id: string) => {
await spotifyAuth.awaitAuth()
const playlist = await get(api.getPlaylist, [id])
playlist.tracks.items = playlist.tracks.items.filter((t) => !t.is_local)
return playlist
const _getPlaylist = async () => {
await spotifyAuth.awaitAuth()
let playlist: SpotifyApi.PlaylistObjectFull | undefined
for await (const batch of retrieveArray(() => api.getPlaylist(id))) {
if (playlist === undefined) {
playlist = batch as SpotifyApi.PlaylistObjectFull
} else if (playlist) {
//@ts-ignore batch type idk, doesn't matter
playlist.tracks.items.push(...batch.items)
}
}
if (playlist === undefined) throw Error('Oh no')
playlist.tracks.items = playlist.tracks.items.filter((t) => !t.is_local)
return playlist
}
return await executeCached(_getPlaylist, `full-playlist-${id}`, 1000 * 60 * 60 * 24)
}
const getAlbum = async (id: string) => await get(api.getAlbum, [id])
const getArtist = async (id: string, useCache = false) =>
Expand Down

0 comments on commit 6473774

Please sign in to comment.