fix(netease): load playlists beyond 1000 tracks

This commit is contained in:
yhxglsa2016 committed 2026-11-28 09:49:35 +08:00
1 parent fc4d472685
commit 0b3bb0c3dd
3 files changed
+69 -4

No files matched your search

+23 -3
View File
@@ -356,10 +356,30 @@ export class NeteaseProvider implements MusicProvider {
}
async getPlaylistSongs(playlistId: string): Promise<Song[]> {
const res = await this.api.get("/playlist/track/all", {
params: { id: playlistId, ...this.cookieParams },
const cookie = this.cookieParams;
const res = await this.api.get("/playlist/detail", {
params: { id: playlistId, ...cookie },
});
return mapNeteaseSongs(res.data?.songs);
const trackIds: { id: number | string }[] = res.data?.playlist?.trackIds;
if (!Array.isArray(trackIds)) throw new Error("网易云返回的歌单曲目列表无效");
// Song detail accepts at most 1000 IDs. Page over the playlist snapshot
// so missing details for unavailable tracks cannot hide a later batch.
const batchSize = 1000;
const songs: Song[] = [];
for (let offset = 0; offset < trackIds.length; offset += batchSize) {
const ids = trackIds.slice(offset, offset + batchSize).map(track => String(track.id));
// The sidecar's URL-based cache cannot distinguish POST bodies.
const details = await this.api.post("/song/detail", { ids: ids.join(","), ...cookie }, {
headers: { "x-apicache-bypass": "1" },
});
if (!Array.isArray(details.data?.songs)) throw new Error("网易云返回的歌曲详情无效");
const byId = new Map(mapNeteaseSongs(details.data.songs).map(song => [song.id, song]));
for (const id of ids) {
const song = byId.get(id);
if (song) songs.push(song);
}
}
return songs;
}
async getRecommendPlaylists(): Promise<Playlist[]> {