diff --git a/BBDown.Core/APP/Payload/playviewreq.proto b/BBDown.Core/APP/Payload/playviewreq.proto index b47fdfd56..328bb0870 100644 --- a/BBDown.Core/APP/Payload/playviewreq.proto +++ b/BBDown.Core/APP/Payload/playviewreq.proto @@ -17,6 +17,7 @@ message PlayViewReq { NOCODE = 0; CODE264 = 1; CODE265 = 2; + CODEAV1 = 3; } optional CodeType preferCodecType = 12; optional bool isPreview = 13; diff --git a/BBDown.Core/AppHelper.cs b/BBDown.Core/AppHelper.cs index 223612673..5d27061eb 100644 --- a/BBDown.Core/AppHelper.cs +++ b/BBDown.Core/AppHelper.cs @@ -33,6 +33,17 @@ class AppHelper private static readonly string region = "CN"; private static readonly string language = "zh"; + private static PlayViewReq.Types.CodeType GetVideoCodeType(string code) + { + return code switch + { + "AVC" => PlayViewReq.Types.CodeType.Code264, + "HEVC" => PlayViewReq.Types.CodeType.Code265, + "AV1" => PlayViewReq.Types.CodeType.Codeav1, + _ => PlayViewReq.Types.CodeType.Code265 + }; + } + /// /// 发起请求并返回响应报文(protobuf -> json) /// @@ -41,11 +52,11 @@ class AppHelper /// /// /// - public static async Task DoReqAsync(string aid, string cid, string epId, string qn, bool bangumi, bool onlyAvc, string appkey = "") + public static async Task DoReqAsync(string aid, string cid, string epId, string qn, bool bangumi, string encoding, string appkey = "") { var headers = GetHeader(appkey); LogDebug("App-Req-Headers: {0}", JsonSerializer.Serialize(headers, JsonContext.Default.DictionaryStringString)); - var body = GetPayload(Convert.ToInt64(aid), Convert.ToInt64(cid), Convert.ToInt64(qn), onlyAvc ? PlayViewReq.Types.CodeType.Code264 : PlayViewReq.Types.CodeType.Code265); + var body = GetPayload(Convert.ToInt64(aid), Convert.ToInt64(cid), Convert.ToInt64(qn), GetVideoCodeType(encoding)); //Console.WriteLine(ReadMessage(body)); var data = await GetPostResponseAsync(API, body, headers); PlayViewReply? resp; @@ -62,7 +73,7 @@ public static async Task DoReqAsync(string aid, string cid, string epId, if (bangumi) { - body = GetPayload(Convert.ToInt64(epId), Convert.ToInt64(cid), Convert.ToInt64(qn), onlyAvc ? PlayViewReq.Types.CodeType.Code264 : PlayViewReq.Types.CodeType.Code265); + body = GetPayload(Convert.ToInt64(epId), Convert.ToInt64(cid), Convert.ToInt64(qn), GetVideoCodeType(encoding)); data = await GetPostResponseAsync(API2, body, headers); resp = new MessageParser(() => new PlayViewReply()).ParseFrom(ReadMessage(data)); } @@ -95,6 +106,7 @@ private static string ConvertToDashJson(object data) videos.Add(new AudioInfoWitCodecId( item.StreamInfo.Quality, item.DashVideo.BaseUrl, + item.DashVideo.BackupUrl.ToList(), (uint)(item.DashVideo.Size * 8 / (resp.VideoInfo.Timelength / 1000)), item.DashVideo.Codecid )); @@ -150,8 +162,8 @@ private static byte[] GetPayload(long aid, long cid, long qn, PlayViewReq.Types. EpId = aid, Cid = cid, //obj.Qn = qn; - Qn = 126, - Fnval = 976, + Qn = 127, + Fnval = 4048, Spmid = "main.ugc-video-detail.0.0", FromSpmid = "main.my-history.0.0", PreferCodecType = codec, @@ -378,7 +390,7 @@ internal class AudioInfoWithCodecName [JsonPropertyName("codecs")] public string Codecs { get; } - public AudioInfoWithCodecName(uint id, string base_url,List backup_url, uint bandwidth, string codecs) + public AudioInfoWithCodecName(uint id, string base_url, List backup_url, uint bandwidth, string codecs) { Id = id; BaseUrl = base_url; @@ -397,15 +409,18 @@ internal class AudioInfoWitCodecId public uint Id { get; } [JsonPropertyName("base_url")] public string BaseUrl { get; } + [JsonPropertyName("backup_url")] + public List BackupUrl { get; } [JsonPropertyName("bandwidth")] public uint Bandwidth { get; } [JsonPropertyName("codecid")] public uint Codecid { get; } - public AudioInfoWitCodecId(uint id, string base_url, uint bandwidth, uint codecid) + public AudioInfoWitCodecId(uint id, string base_url, List backup_url, uint bandwidth, uint codecid) { Id = id; BaseUrl = base_url; + BackupUrl = backup_url; Bandwidth = bandwidth; Codecid = codecid; } diff --git a/BBDown.Core/Parser.cs b/BBDown.Core/Parser.cs index 2418cd687..db5b6b4af 100644 --- a/BBDown.Core/Parser.cs +++ b/BBDown.Core/Parser.cs @@ -15,7 +15,7 @@ public static string WbiSign(string api) return $"{api}&w_rid=" + string.Concat(MD5.HashData(Encoding.UTF8.GetBytes(api + Config.WBI)).Select(i => i.ToString("x2")).ToArray()); } - private static async Task GetPlayJsonAsync(bool onlyAvc, string aidOri, string aid, string cid, string epId, bool tvApi, bool intl, bool appApi, string qn = "0") + private static async Task GetPlayJsonAsync(string encoding, string aidOri, string aid, string cid, string epId, bool tvApi, bool intl, bool appApi, string qn = "0") { LogDebug("aid={0},cid={1},epId={2},tvApi={3},IntlApi={4},appApi={5},qn={6}", aid, cid, epId, tvApi, intl, appApi, qn); @@ -26,7 +26,7 @@ private static async Task GetPlayJsonAsync(bool onlyAvc, string aidOri, bool bangumi = cheese || aidOri.StartsWith("ep:"); LogDebug("bangumi={0},cheese={1}", bangumi, cheese); - if (appApi) return await AppHelper.DoReqAsync(aid, cid, epId, qn, bangumi, onlyAvc, Config.TOKEN); + if (appApi) return await AppHelper.DoReqAsync(aid, cid, epId, qn, bangumi, encoding, Config.TOKEN); string prefix = tvApi ? bangumi ? "api.snm0516.aisee.tv/pgc/player/api/playurltv" : "api.snm0516.aisee.tv/x/tv/ugc/playurl" : bangumi ? $"{Config.HOST}/pgc/player/web/playurl" : "api.bilibili.com/x/player/wbi/playurl"; @@ -85,13 +85,7 @@ private static async Task GetPlayJsonAsync(string aid, string cid, strin return webJson; } - public static string SkiPcdn(List urlList, string baseUrl) - { - urlList.Add(baseUrl); - return urlList.FirstOrDefault(i => !PcdnRegex().IsMatch(i), urlList.First()); - } - - public static async Task<(string, List