From 602e29ce8d13c4e17487c3fa6ee5795422fb1d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E5=BD=AA?= <1315508912@qq.com> Date: Mon, 4 Mar 2024 23:43:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BD=BF=E7=94=A8Web?= =?UTF-8?q?Page=E6=96=B9=E5=BC=8F=E8=A7=A3=E6=9E=90=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=A3=8E=E6=8E=A7=E9=97=AE=E9=A2=98(=E4=BB=85=E9=99=90?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E8=A7=86=E9=A2=91=EF=BC=8C=E7=95=AA=E5=89=A7?= =?UTF-8?q?=E3=80=81=E8=AF=BE=E7=A8=8B=E6=9C=AA=E5=AE=9E=E7=8E=B0)=20#37?= =?UTF-8?q?=20#36?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BiliApi/BiliUtils/VideoParseType.cs | 7 + .../BiliApi/VideoStream/VideoStream.cs | 78 +++- DownKyi.Core/Settings/Models/VideoSettings.cs | 1 + .../Settings/SettingsManager.Video.cs | 31 ++ DownKyi/Languanges/Default.axaml | 1 + DownKyi/Models/DownloadBase.cs | 3 + .../Services/Download/AddToDownloadService.cs | 3 +- DownKyi/Services/Download/DownloadService.cs | 8 +- DownKyi/Services/VideoInfoService.cs | 15 +- .../ViewModels/PageViewModels/VideoPage.cs | 2 + .../ViewModels/Settings/ViewVideoViewModel.cs | 423 +++++++++--------- DownKyi/Views/Settings/ViewVideo.axaml | 21 + 12 files changed, 361 insertions(+), 232 deletions(-) create mode 100644 DownKyi.Core/BiliApi/BiliUtils/VideoParseType.cs diff --git a/DownKyi.Core/BiliApi/BiliUtils/VideoParseType.cs b/DownKyi.Core/BiliApi/BiliUtils/VideoParseType.cs new file mode 100644 index 0000000..553dfac --- /dev/null +++ b/DownKyi.Core/BiliApi/BiliUtils/VideoParseType.cs @@ -0,0 +1,7 @@ +namespace DownKyi.Core.BiliApi.BiliUtils; + +public class VideoParseType +{ + public string? Name { get; set; } + public int? Id { get; set; } +} \ No newline at end of file diff --git a/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs b/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs index 59f1974..6fecec0 100644 --- a/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs +++ b/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs @@ -1,4 +1,5 @@ -using DownKyi.Core.BiliApi.Models.Json; +using System.Text.RegularExpressions; +using DownKyi.Core.BiliApi.Models.Json; using DownKyi.Core.BiliApi.Sign; using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Logging; @@ -128,12 +129,34 @@ public static class VideoStream return null; } - string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); - string url = $"https://api.bilibili.com/x/player/wbi/playurl?{query}"; + var query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + var url = $"https://api.bilibili.com/x/player/wbi/playurl?{query}"; return GetPlayUrl(url); } + /// + /// 获取普通视频的视频流(WebPage方式) + /// + /// + /// + /// + /// + public static PlayUrl GetVideoPlayUrlWebPage(long avid, string bvid, int p) + { + var url = "https://www.bilibili.com/video"; + if (bvid == string.Empty) + { + url = $"{url}/{bvid}/?p={p}"; + } + else if (avid > -1) + { + url = $"{url}/av{avid}/?p={p}"; + } + + return GetPlayUrlWebPage(url); + } + /// /// 获取番剧的视频流 /// @@ -205,8 +228,8 @@ public static class VideoStream /// private static PlayUrl GetPlayUrl(string url) { - string referer = "https://m.bilibili.com"; - string response = WebClient.RequestWeb(url, referer); + const string referer = "https://m.bilibili.com"; + var response = WebClient.RequestWeb(url, referer); try { @@ -235,4 +258,49 @@ public static class VideoStream return null; } } + + /// + /// 获取视频流(WebPage方式) + /// + /// + /// + private static PlayUrl GetPlayUrlWebPage(string url) + { + const string referer = "https://www.bilibili.com"; + var response = WebClient.RequestWeb(url, referer); + + try + { + var regex = new Regex(@"