Skip to content

Commit

Permalink
识别[智能修复]画质 (#925)
Browse files Browse the repository at this point in the history
close #924
  • Loading branch information
UnforgetMemory authored Sep 1, 2024
1 parent 45622f7 commit 99f9ed4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion BBDown.Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Config

public static readonly Dictionary<string, string> qualitys = new() {
{"127","8K 超高清" }, {"126","杜比视界" }, {"125","HDR 真彩" }, {"120","4K 超清" }, {"116","1080P 高帧率" },
{"112","1080P 高码率" }, {"80","1080P 高清" }, {"74","720P 高帧率" },
{"112","1080P 高码率" }, {"100","智能修复" }, {"80","1080P 高清" }, {"74","720P 高帧率" },
{"64","720P 高清" }, {"48","720P 高清" }, {"32","480P 清晰" }, {"16","360P 流畅" },
{"5","144P 流畅" }, {"6","240P 流畅" }
};
Expand Down
45 changes: 28 additions & 17 deletions BBDown.Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static async Task<string> GetPlayJsonAsync(string encoding, string aidOr
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/playurl"
: bangumi ? $"{Config.HOST}/pgc/player/web/playurl" : "api.bilibili.com/x/player/wbi/playurl";
: bangumi ? $"{Config.HOST}/pgc/player/web/v2/playurl" : "api.bilibili.com/x/player/wbi/playurl";
prefix = $"https://{prefix}?";

string api;
Expand All @@ -48,7 +48,7 @@ private static async Task<string> GetPlayJsonAsync(string encoding, string aidOr
{
// 尝试提高可读性
StringBuilder apiBuilder = new();
apiBuilder.Append($"avid={aid}&cid={cid}&fnval=4048&fnver=0&fourk=1");
apiBuilder.Append($"support_multi_audio=true&from_client=BROWSER&avid={aid}&cid={cid}&fnval=4048&fnver=0&fourk=1");
if (Config.AREA != "") apiBuilder.Append($"&access_key={Config.TOKEN}&area={Config.AREA}");
apiBuilder.Append($"&otype=json&qn={qn}");
if (bangumi) apiBuilder.Append($"&module=bangumi&ep_id={epId}&session=");
Expand Down Expand Up @@ -100,6 +100,8 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
//调用解析
parsedResult.WebJsonString = await GetPlayJsonAsync(encoding, aidOri, aid, cid, epId, tvApi, intlApi, appApi, qn);

LogDebug(parsedResult.WebJsonString);

startParsing:
var respJson = JsonDocument.Parse(parsedResult.WebJsonString);
var data = respJson.RootElement;
Expand All @@ -109,7 +111,7 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
{
int pDur = data.GetProperty("data").GetProperty("video_info").GetProperty("timelength").GetInt32() / 1000;
var audio = data.GetProperty("data").GetProperty("video_info").GetProperty("dash_audio").EnumerateArray().ToList();
foreach(var stream in data.GetProperty("data").GetProperty("video_info").GetProperty("stream_list").EnumerateArray())
foreach (var stream in data.GetProperty("data").GetProperty("video_info").GetProperty("stream_list").EnumerateArray())
{
if (stream.TryGetProperty("dash_video", out JsonElement dashVideo))
{
Expand All @@ -133,7 +135,7 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
}
}

foreach(var node in audio)
foreach (var node in audio)
{
var urlList = new List<string>() { node.GetProperty("base_url").ToString() };
urlList.AddRange(node.GetProperty("backup_url").EnumerateArray().Select(i => i.ToString()));
Expand All @@ -160,9 +162,18 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
}
// data节点一次性判断完
string nodeName = null;
if (parsedResult.WebJsonString.Contains("\"result\":{")) nodeName = "result";
if (parsedResult.WebJsonString.Contains("\"result\":{"))
{
nodeName = "result";

// v2
if (parsedResult.WebJsonString.Contains("\"video_info\":{"))
{
nodeName = "video_info";
}
}
else if (parsedResult.WebJsonString.Contains("\"data\":{")) nodeName = "data";
var root = nodeName == null ? data : data.GetProperty(nodeName);
var root = nodeName == null ? data : nodeName == "video_info" ? data.GetProperty("result").GetProperty(nodeName) : data.GetProperty(nodeName);

bool bangumi = aidOri.StartsWith("ep:");

Expand All @@ -184,15 +195,15 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
parsedResult.WebJsonString = await GetPlayJsonAsync(encoding, aidOri, aid, cid, epId, tvApi, intlApi, appApi, GetMaxQn());
respJson = JsonDocument.Parse(parsedResult.WebJsonString);
data = respJson.RootElement;
root = nodeName == null ? data : data.GetProperty(nodeName);
root = nodeName == null ? data : nodeName == "video_info" ? data.GetProperty("result").GetProperty(nodeName) : data.GetProperty(nodeName);
}
try { video = root.GetProperty("dash").GetProperty("video").EnumerateArray().ToList(); } catch { }
try { audio = root.GetProperty("dash").GetProperty("audio").EnumerateArray().ToList(); } catch { }

if (appApi && bangumi)
{
try { backgroundAudio = data.GetProperty("dubbing_info").GetProperty("background_audio").EnumerateArray().ToList(); } catch { }
try { roleAudio = data.GetProperty("dubbing_info").GetProperty("role_audio_list").EnumerateArray().ToList(); } catch { }
try { backgroundAudio = data.GetProperty("dubbing_info").GetProperty("background_audio").EnumerateArray().ToList(); } catch { }
try { roleAudio = data.GetProperty("dubbing_info").GetProperty("role_audio_list").EnumerateArray().ToList(); } catch { }
}
//处理杜比音频
try
Expand All @@ -208,7 +219,7 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
}
}
}
catch (Exception) { ; }
catch (Exception) {; }

//处理Hi-Res无损
try
Expand All @@ -232,7 +243,7 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
foreach (var node in video)
{
var urlList = new List<string>() { node.GetProperty("base_url").ToString() };
if(node.TryGetProperty("backup_url", out JsonElement element) && element.ValueKind != JsonValueKind.Null)
if (node.TryGetProperty("backup_url", out JsonElement element) && element.ValueKind != JsonValueKind.Null)
{
urlList.AddRange(element.EnumerateArray().Select(i => i.ToString()));
}
Expand Down Expand Up @@ -346,7 +357,7 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
//默认以最高清晰度解析
parsedResult.WebJsonString = await GetPlayJsonAsync(encoding, aidOri, aid, cid, epId, tvApi, intlApi, appApi, GetMaxQn());
data = JsonDocument.Parse(parsedResult.WebJsonString).RootElement;
root = nodeName == null ? data : data.GetProperty(nodeName);
root = nodeName == null ? data : nodeName == "video_info" ? data.GetProperty("result").GetProperty(nodeName) : data.GetProperty(nodeName);
string quality = "";
string videoCodecid = "";
string url = "";
Expand Down Expand Up @@ -392,11 +403,11 @@ public static async Task<ParsedResult> ExtractTracksAsync(string aidOri, string
if (root.TryGetProperty("clip_info_list", out JsonElement clipList))
{
parsedResult.ExtraPoints.AddRange(clipList.EnumerateArray().Select(clip => new ViewPoint()
{
title = clip.GetProperty("toastText").ToString().Replace("即将跳过", ""),
start = clip.GetProperty("start").GetInt32(),
end = clip.GetProperty("end").GetInt32()
})
{
title = clip.GetProperty("toastText").ToString().Replace("即将跳过", ""),
start = clip.GetProperty("start").GetInt32(),
end = clip.GetProperty("end").GetInt32()
})
);
parsedResult.ExtraPoints.Sort((p1, p2) => p1.start.CompareTo(p2.start));
var newPoints = new List<ViewPoint>();
Expand Down

0 comments on commit 99f9ed4

Please sign in to comment.