From 341faffdbbdc1c778d628d46f9a2479a269811e1 Mon Sep 17 00:00:00 2001 From: saopig1 Date: Mon, 30 Mar 2026 19:40:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20B=E7=AB=99=E5=B0=81=E9=9D=A2=20=E2=80=94?= =?UTF-8?q?=20http=E8=BD=AChttps=E9=98=B2=E6=AD=A2mixed=20content=EF=BC=8C?= =?UTF-8?q?CDN=E5=8F=82=E6=95=B0@300w=5F300h=5F1c=E6=AD=A3=E6=96=B9?= =?UTF-8?q?=E5=BD=A2=E8=A3=81=E5=88=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- src/music/bilibili.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/music/bilibili.ts b/src/music/bilibili.ts index 15bf828..cfd21ed 100644 --- a/src/music/bilibili.ts +++ b/src/music/bilibili.ts @@ -53,6 +53,20 @@ export class BiliBiliProvider implements MusicProvider { return str.replace(/<[^>]+>/g, ""); } + /** Normalize B站 cover URL: fix protocol, add square crop via CDN param */ + private normalizeCover(url: string): string { + if (!url) return ""; + let fixed = url; + if (fixed.startsWith("//")) fixed = `https:${fixed}`; + else if (fixed.startsWith("http://")) fixed = fixed.replace("http://", "https://"); + // B站 CDN supports @{w}w_{h}h_1c for center crop + // Append square crop if no @ params exist + if (!fixed.includes("@") && (fixed.includes("hdslb.com") || fixed.includes("bilibili.com"))) { + fixed += "@300w_300h_1c"; + } + return fixed; + } + async search(query: string, limit = 20): Promise { const res = await this.api.get("/x/web-interface/search/type", { params: { @@ -74,11 +88,7 @@ export class BiliBiliProvider implements MusicProvider { ? this.parseDurationString(v.duration) : v.duration : 0, - coverUrl: v.pic - ? v.pic.startsWith("//") - ? `https:${v.pic}` - : v.pic - : "", + coverUrl: this.normalizeCover(v.pic ?? ""), platform: "bilibili" as const, })); @@ -115,7 +125,7 @@ export class BiliBiliProvider implements MusicProvider { artist: data.owner?.name ?? "", album: "", duration: data.duration ?? 0, - coverUrl: data.pic ?? "", + coverUrl: this.normalizeCover(data.pic ?? ""), platform: "bilibili" as const, }; } catch {