From 50f82e15f3b7e78b50b870f99833dc8346b099a0 Mon Sep 17 00:00:00 2001 From: Haisei Date: Mon, 29 Jun 2026 02:48:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87=20?= =?UTF-8?q?CDN=20=E5=8A=A0=E8=BD=BD=E8=A7=86=E9=A2=91/=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Media/PlayParse/Bilibili_Config.json | 3 ++ Media/PlayParse/MediaPlayParse - Bilibili.as | 42 ++++++++++++++++---- README.md | 7 ++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Media/PlayParse/Bilibili_Config.json b/Media/PlayParse/Bilibili_Config.json index a1d0533..40d2684 100644 --- a/Media/PlayParse/Bilibili_Config.json +++ b/Media/PlayParse/Bilibili_Config.json @@ -19,5 +19,8 @@ }, // 播放单个视频时是否显示推荐的视频 "showRecommendedVideos": true, + // 首选视频 CDN 域名。填入后,视频/音频地址的 host 会被替换为它。 + // 留空则使用 B 站默认返回的地址。 + "cdnHost": "", "debug": false } \ No newline at end of file diff --git a/Media/PlayParse/MediaPlayParse - Bilibili.as b/Media/PlayParse/MediaPlayParse - Bilibili.as index ab0ac53..0ca2c25 100644 --- a/Media/PlayParse/MediaPlayParse - Bilibili.as +++ b/Media/PlayParse/MediaPlayParse - Bilibili.as @@ -127,6 +127,7 @@ class Config { float danmakuStayTime = 15.0; bool showRecommendedVideos = true; bool debug = false; + string cdnHost; string danmakuUrl; string subtitleUrl; @@ -183,6 +184,17 @@ Config ReadConfigFile(string file) { if (root["debug"].isBool()) { config.debug = root["debug"].asBool(); } + if (root["cdnHost"].isString()) { + string host = root["cdnHost"].asString(); + int schemeEnd = host.find("://"); + if (schemeEnd >= 0) { + host = host.substr(schemeEnd + 3); + } + while (host.length() > 0 && host.substr(host.length() - 1, 1) == "/") { + host = host.substr(0, host.length() - 1); + } + config.cdnHost = host; + } if (!config.danmakuServer.empty()) { config.danmakuUrl = config.danmakuServer + "/subtitle?font=" + HostUrlEncode(config.danmakuFont) + "&font_size=" + config.danmakuFontSize + "&alpha=" + config.danmakuOpacity + "&display_area=" + config.danmakuDisplayArea + "&duration_marquee=" + config.danmakuStayTime + "&duration_still=" + config.danmakuStayTime + "&cid="; config.subtitleUrl = config.danmakuServer + "/subtitle?url="; @@ -229,6 +241,22 @@ void log(string item, int info) { log(item + ": " + info); } +string replaceCdnHost(string url) { + if (ConfigData.cdnHost.empty() || url.empty()) { + return url; + } + int p = url.find("://"); + if (p < 0) { + return url; + } + int hostStart = p + 3; + int pathStart = url.find("/", hostStart); + if (pathStart < 0) { + return url; + } + return url.substr(0, hostStart) + ConfigData.cdnHost + url.substr(pathStart); +} + string post(string url, string data="") { string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"; string Headers = "Referer: https://www.bilibili.com\r\n"; @@ -534,7 +562,7 @@ string Video(string bvid, const string &in path, dictionary &MetaData, array 0) { - qualityitem2["url"] = data["durl"][0]["backup_url"][0].asString(); + qualityitem2["url"] = replaceCdnHost(data["durl"][0]["backup_url"][0].asString()); } else { qualityitem2["url"] = url; } diff --git a/README.md b/README.md index 9a5f224..8f5c477 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ [获取Cookie](https://github.com/chen310/BilibiliPotPlayer/issues/62#issuecomment-1841909583) +### 指定视频 CDN + +如果默认加载视频较慢,可在 `Bilibili_Config.json` +中填写 `cdnHost`,把视频/音频地址的 host 替换为指定的 CDN。留空则使用 B 站默认地址。 + +替换 host 后可能无法播放;此时可清空 `cdnHost` 恢复默认。 + ## 使用方法 ### 播放视频/直播