mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 21:12:49 +08:00
fix(bilibili): 修复了B站分P视频播放时只能播放第一P,且时长显示为视频总时长
在网页端播放多P视频时弹出界面选择需要播放的P数,ts里!play播放则只播放第一P
This commit is contained in:
1 parent
2ea02f54d9
commit
3c0e8df763
9 files changed
+795
-16
No files matched your search
@@ -438,3 +438,68 @@ describe("music router POST /local/upload — content types and size cap (#149)"
|
||||
expect(uploadAudio).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("music router GET /bilibili/parts", () => {
|
||||
it("returns 400 when bvid is missing", async () => {
|
||||
const router = createMusicRouter(
|
||||
fakeProvider("netease"),
|
||||
fakeProvider("qq"),
|
||||
fakeProvider("bilibili"),
|
||||
pino({ level: "silent" })
|
||||
);
|
||||
const app = express();
|
||||
app.use("/api/music", router);
|
||||
|
||||
const res = await request(app).get("/api/music/bilibili/parts");
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toBe("bvid is required");
|
||||
});
|
||||
|
||||
it("returns parts from bilibili provider when available", async () => {
|
||||
const mockBilibili = {
|
||||
platform: "bilibili" as const,
|
||||
search: vi.fn(),
|
||||
getVideoParts: vi.fn().mockResolvedValue({
|
||||
bvid: "BV1test",
|
||||
title: "多P视频测试",
|
||||
parts: [
|
||||
{ part: 1, cid: 101, title: "P1", duration: 100 },
|
||||
{ part: 2, cid: 102, title: "P2", duration: 200 },
|
||||
],
|
||||
}),
|
||||
};
|
||||
const router = createMusicRouter(
|
||||
fakeProvider("netease"),
|
||||
fakeProvider("qq"),
|
||||
mockBilibili as unknown as MusicProvider,
|
||||
pino({ level: "silent" })
|
||||
);
|
||||
const app = express();
|
||||
app.use("/api/music", router);
|
||||
|
||||
const res = await request(app).get("/api/music/bilibili/parts?bvid=BV1test");
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.bvid).toBe("BV1test");
|
||||
expect(res.body.parts).toHaveLength(2);
|
||||
expect(mockBilibili.getVideoParts).toHaveBeenCalledWith("BV1test");
|
||||
});
|
||||
|
||||
it("returns 404 when getVideoParts returns null", async () => {
|
||||
const mockBilibili = {
|
||||
platform: "bilibili" as const,
|
||||
search: vi.fn(),
|
||||
getVideoParts: vi.fn().mockResolvedValue(null),
|
||||
};
|
||||
const router = createMusicRouter(
|
||||
fakeProvider("netease"),
|
||||
fakeProvider("qq"),
|
||||
mockBilibili as unknown as MusicProvider,
|
||||
pino({ level: "silent" })
|
||||
);
|
||||
const app = express();
|
||||
app.use("/api/music", router);
|
||||
|
||||
const res = await request(app).get("/api/music/bilibili/parts?bvid=BV1notfound");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
@@ -382,6 +382,31 @@ export function createMusicRouter(
|
||||
}
|
||||
});
|
||||
|
||||
// B站分P列表查询
|
||||
router.get("/bilibili/parts", async (req, res) => {
|
||||
try {
|
||||
const bvid = (req.query.bvid as string)?.trim();
|
||||
if (!bvid) {
|
||||
res.status(400).json({ error: "bvid is required" });
|
||||
return;
|
||||
}
|
||||
const provider = bilibiliProvider as any;
|
||||
if (typeof provider.getVideoParts === "function") {
|
||||
const result = await provider.getVideoParts(bvid);
|
||||
if (!result) {
|
||||
res.status(404).json({ error: "Video not found" });
|
||||
return;
|
||||
}
|
||||
res.json(result);
|
||||
} else {
|
||||
res.status(501).json({ error: "Not supported" });
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Get bilibili parts failed");
|
||||
res.status(500).json({ error: (err as Error).message });
|
||||
}
|
||||
});
|
||||
|
||||
// Enabled sources + default platform, for the web UI (source tabs, default
|
||||
// search/playback source). Without a config (unit-test routers) everything
|
||||
// reports enabled with the legacy netease default.
|
||||
|
||||
Reference in new issue
Block a user