From 0b3bb0c3dd3b5fc49318a7804c04fea99e9d4e36 Mon Sep 17 00:00:00 2001 From: yhxglsa2016 <1960945492@qq.com> Date: Sat, 28 Nov 2026 09:49:35 +0800 Subject: [PATCH 1/3] fix(netease): load playlists beyond 1000 tracks --- README.md | 2 +- src/music/netease.test.ts | 45 +++++++++++++++++++++++++++++++++++++++ src/music/netease.ts | 26 +++++++++++++++++++--- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 83f339e..8f664ce 100644 --- a/README.md +++ b/README.md @@ -423,7 +423,7 @@ QQ 音源启用时,`QQ_MUSIC_MANAGED_SESSION` 默认为 `1`。在 **设置 → | `!queue` | 查看播放队列 | | `!remove <位置>` | 从队列中删除指定位置的歌曲(位置从 1 开始,见 `!queue`) | | `!mode ` | 切换播放模式 | -| `!playlist <歌单名或ID>` | 加载歌单(支持名称模糊搜索和 ID;Jellyfin 歌单 GUID 也可直接粘贴) | +| `!playlist <歌单名或ID>` | 加载歌单(支持名称模糊搜索和 ID;Jellyfin 歌单 GUID 也可直接粘贴)。超过 1000 首的网易云歌单会按原顺序分批加载,网页歌单详情和「播放全部」同样支持 | | `!playlist -q <歌单名>` | 从 QQ 音乐搜索并加载歌单 | | `!playlist <歌单链接>` | 直接粘贴网易云 / QQ 音乐 / YouTube 歌单链接加载,平台由链接自动识别,无需加 `-q` 等标志;也可直接粘贴 App 的分享文案或短链(`163cn.tv`、`c6.y.qq.com`) | | `!album <专辑名或ID>` | 加载专辑(支持名称搜索 / 数字 ID / Jellyfin GUID) | diff --git a/src/music/netease.test.ts b/src/music/netease.test.ts index 3c0dbb1..fafa95e 100644 --- a/src/music/netease.test.ts +++ b/src/music/netease.test.ts @@ -237,6 +237,51 @@ describe("NeteaseProvider.search pagination", () => { }); }); +describe("NeteaseProvider.getPlaylistSongs (#200)", () => { + function playlistFixture(size: number) { + const ids = Array.from({ length: size }, (_, i) => i + 1); + const get = vi.fn().mockResolvedValue({ + data: { playlist: { trackIds: ids.map(id => ({ id })) } }, + }); + const post = vi.fn(async (_path: string, body: { ids: string }) => ({ + data: { songs: body.ids.split(",").reverse().map(id => ({ id: Number(id) })) }, + })); + const provider = new NeteaseProvider("http://x"); + provider.setCookie("MUSIC_U=test"); + (provider as any).api = { get, post }; + return { provider, ids, get, post }; + } + + it.each([0, 12, 1000, 1360, 2000])("loads %i tracks in playlist order", async size => { + const { provider, ids, get, post } = playlistFixture(size); + const songs = await provider.getPlaylistSongs("920292129"); + expect(songs.map(song => song.id)).toEqual(ids.map(String)); + expect(get.mock.calls).toEqual([["/playlist/detail", { + params: { id: "920292129", cookie: "MUSIC_U=test" }, + }]]); + expect(post).toHaveBeenCalledTimes(Math.ceil(size / 1000)); + for (let offset = 0; offset < size; offset += 1000) { + expect(post).toHaveBeenNthCalledWith(offset / 1000 + 1, "/song/detail", { + ids: ids.slice(offset, offset + 1000).join(","), cookie: "MUSIC_U=test", + }, { headers: { "x-apicache-bypass": "1" } }); + } + }); + + it("continues past unavailable tracks in an earlier batch", async () => { + const { provider, post } = playlistFixture(1002); + post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } }); + const songs = await provider.getPlaylistSongs("920292129"); + expect(songs.map(song => song.id)).toEqual(["1", "1001", "1002"]); + }); + + it("propagates a failed batch instead of returning a partial playlist", async () => { + const { provider, post } = playlistFixture(1360); + post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } }) + .mockRejectedValueOnce(new Error("sidecar unavailable")); + await expect(provider.getPlaylistSongs("920292129")).rejects.toThrow("sidecar unavailable"); + }); +}); + describe("mapNeteaseArtists (artist search + detail)", () => { it("maps cloudsearch type=100 artist entries", () => { const out = mapNeteaseArtists([ diff --git a/src/music/netease.ts b/src/music/netease.ts index a8fc2c6..0d4cd80 100644 --- a/src/music/netease.ts +++ b/src/music/netease.ts @@ -356,10 +356,30 @@ export class NeteaseProvider implements MusicProvider { } async getPlaylistSongs(playlistId: string): Promise { - 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 { From 11081ec4f84a7b2d88b78d387a4908cc710f0535 Mon Sep 17 00:00:00 2001 From: yhxglsa2016 <1960945492@qq.com> Date: Sat, 28 Nov 2026 11:51:20 +0800 Subject: [PATCH 2/3] fix(netease): use eapi for playlist track details --- src/music/netease.test.ts | 2 +- src/music/netease.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/music/netease.test.ts b/src/music/netease.test.ts index fafa95e..b37501d 100644 --- a/src/music/netease.test.ts +++ b/src/music/netease.test.ts @@ -262,7 +262,7 @@ describe("NeteaseProvider.getPlaylistSongs (#200)", () => { expect(post).toHaveBeenCalledTimes(Math.ceil(size / 1000)); for (let offset = 0; offset < size; offset += 1000) { expect(post).toHaveBeenNthCalledWith(offset / 1000 + 1, "/song/detail", { - ids: ids.slice(offset, offset + 1000).join(","), cookie: "MUSIC_U=test", + ids: ids.slice(offset, offset + 1000).join(","), cookie: "MUSIC_U=test", crypto: "eapi", }, { headers: { "x-apicache-bypass": "1" } }); } }); diff --git a/src/music/netease.ts b/src/music/netease.ts index 0d4cd80..fd7d792 100644 --- a/src/music/netease.ts +++ b/src/music/netease.ts @@ -368,8 +368,13 @@ export class NeteaseProvider implements MusicProvider { 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 }, { + const details = await this.api.post("/song/detail", { + ids: ids.join(","), + // Match /playlist/track/all's detail lookup; /song/detail defaults to weapi. + crypto: "eapi", + ...cookie, + }, { + // The sidecar's URL-based cache cannot distinguish POST bodies. headers: { "x-apicache-bypass": "1" }, }); if (!Array.isArray(details.data?.songs)) throw new Error("网易云返回的歌曲详情无效"); From a44324b7488d8fd73a441dcaff4fc15ce9000253 Mon Sep 17 00:00:00 2001 From: yhxglsa2016 <1960945492@qq.com> Date: Sat, 28 Nov 2026 12:08:19 +0800 Subject: [PATCH 3/3] fix(netease): warn about missing playlist track details After all batches succeed, log one warning with the playlist ID and expected, matched, and missing track counts. Return the matched tracks in playlist order. --- src/index.ts | 2 +- src/music/netease.test.ts | 17 +++++++++++------ src/music/netease.ts | 13 +++++++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 796831f..0c60ed5 100755 --- a/src/index.ts +++ b/src/index.ts @@ -67,7 +67,7 @@ async function main() { ); await apiServer.start(); - const neteaseProvider = new NeteaseProvider(apiServer.getNeteaseBaseUrl()); + const neteaseProvider = new NeteaseProvider(apiServer.getNeteaseBaseUrl(), logger); const bilibiliProvider = new BiliBiliProvider(); const localProvider = new LocalMusicProvider(LOCAL_AUDIO_DIR); const kugouProvider = new KugouProvider(); diff --git a/src/music/netease.test.ts b/src/music/netease.test.ts index b37501d..57e20f0 100644 --- a/src/music/netease.test.ts +++ b/src/music/netease.test.ts @@ -239,6 +239,7 @@ describe("NeteaseProvider.search pagination", () => { describe("NeteaseProvider.getPlaylistSongs (#200)", () => { function playlistFixture(size: number) { + const warn = vi.fn(); const ids = Array.from({ length: size }, (_, i) => i + 1); const get = vi.fn().mockResolvedValue({ data: { playlist: { trackIds: ids.map(id => ({ id })) } }, @@ -246,16 +247,16 @@ describe("NeteaseProvider.getPlaylistSongs (#200)", () => { const post = vi.fn(async (_path: string, body: { ids: string }) => ({ data: { songs: body.ids.split(",").reverse().map(id => ({ id: Number(id) })) }, })); - const provider = new NeteaseProvider("http://x"); - provider.setCookie("MUSIC_U=test"); + const provider = new NeteaseProvider("http://x", { warn }).withCookie("MUSIC_U=test"); (provider as any).api = { get, post }; - return { provider, ids, get, post }; + return { provider, ids, get, post, warn }; } it.each([0, 12, 1000, 1360, 2000])("loads %i tracks in playlist order", async size => { - const { provider, ids, get, post } = playlistFixture(size); + const { provider, ids, get, post, warn } = playlistFixture(size); const songs = await provider.getPlaylistSongs("920292129"); expect(songs.map(song => song.id)).toEqual(ids.map(String)); + expect(warn).not.toHaveBeenCalled(); expect(get.mock.calls).toEqual([["/playlist/detail", { params: { id: "920292129", cookie: "MUSIC_U=test" }, }]]); @@ -268,17 +269,21 @@ describe("NeteaseProvider.getPlaylistSongs (#200)", () => { }); it("continues past unavailable tracks in an earlier batch", async () => { - const { provider, post } = playlistFixture(1002); + const { provider, post, warn } = playlistFixture(1002); post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } }); const songs = await provider.getPlaylistSongs("920292129"); expect(songs.map(song => song.id)).toEqual(["1", "1001", "1002"]); + expect(warn.mock.calls).toEqual([[{ + playlistId: "920292129", expectedCount: 1002, matchedCount: 3, missingCount: 999, + }, "NetEase playlist track IDs missing song details"]]); }); it("propagates a failed batch instead of returning a partial playlist", async () => { - const { provider, post } = playlistFixture(1360); + const { provider, post, warn } = playlistFixture(1360); post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } }) .mockRejectedValueOnce(new Error("sidecar unavailable")); await expect(provider.getPlaylistSongs("920292129")).rejects.toThrow("sidecar unavailable"); + expect(warn).not.toHaveBeenCalled(); }); }); diff --git a/src/music/netease.ts b/src/music/netease.ts index fd7d792..dcc8c1c 100644 --- a/src/music/netease.ts +++ b/src/music/netease.ts @@ -1,5 +1,6 @@ import { normalizeCookie } from "./cookie-normalize.js"; import axios, { type AxiosInstance } from "axios"; +import type { Logger } from "../logger.js"; import { RISK_CONTROL_CODE, RiskControlError, SongUrlUnavailable } from "./provider.js"; import type { PlayFailure } from "./provider.js"; import type { @@ -236,7 +237,7 @@ export class NeteaseProvider implements MusicProvider { private quality = "exhigh"; private readonly baseUrl: string; - constructor(baseUrl: string) { + constructor(baseUrl: string, private readonly logger: Pick = console) { this.baseUrl = baseUrl; this.api = axios.create({ baseURL: baseUrl, @@ -384,6 +385,14 @@ export class NeteaseProvider implements MusicProvider { if (song) songs.push(song); } } + if (songs.length < trackIds.length) { + this.logger.warn({ + playlistId, + expectedCount: trackIds.length, + matchedCount: songs.length, + missingCount: trackIds.length - songs.length, + }, "NetEase playlist track IDs missing song details"); + } return songs; } @@ -533,7 +542,7 @@ export class NeteaseProvider implements MusicProvider { * a web user's personal FM uses their own taste instead of the shared login. */ withCookie(cookie: string): NeteaseProvider { - const view = new NeteaseProvider(this.baseUrl); + const view = new NeteaseProvider(this.baseUrl, this.logger); view.setQuality(this.quality); view.setCookie(cookie); return view;