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(@"