From 1a80a16d19c1bc829690847267e2f384fcea869b Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Fri, 26 May 2023 18:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=86=E9=A2=91=E6=B5=81AP?= =?UTF-8?q?I=E6=94=AF=E6=8C=81wbi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BiliApi/VideoStream/VideoStream.cs | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs index 5764fcd..80c6109 100644 --- a/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs +++ b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs @@ -1,4 +1,5 @@ using DownKyi.Core.BiliApi.Models.Json; +using DownKyi.Core.BiliApi.Sign; using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; @@ -19,7 +20,14 @@ namespace DownKyi.Core.BiliApi.VideoStream /// public static PlayerV2 PlayerV2(long avid, string bvid, long cid) { - string url = $"https://api.bilibili.com/x/player/v2?cid={cid}&aid={avid}&bvid={bvid}"; + var parameters = new Dictionary + { + { "avid", avid }, + { "bvid", bvid }, + { "cid", cid }, + }; + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/player/wbi/v2?{query}"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); @@ -93,11 +101,30 @@ namespace DownKyi.Core.BiliApi.VideoStream /// public static PlayUrl GetVideoPlayUrl(long avid, string bvid, long cid, int quality = 125) { - string baseUrl = $"https://api.bilibili.com/x/player/playurl?cid={cid}&qn={quality}&fourk=1&fnver=0&fnval=4048"; - string url; - if (bvid != null) { url = $"{baseUrl}&bvid={bvid}"; } - else if (avid > -1) { url = $"{baseUrl}&aid={avid}"; } - else { return null; } + var parameters = new Dictionary + { + { "fourk", 1 }, + { "fnver", 0 }, + { "fnval", 4048 }, + { "cid", cid }, + { "qn", quality }, + }; + + if (bvid != null) + { + parameters.Add("bvid", bvid); + } + else if (avid > -1) + { + parameters.Add("aid", avid); + } + else + { + return null; + } + + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/player/wbi/playurl?{query}"; return GetPlayUrl(url); }