Skip to content

Commit

Permalink
修复国际版api (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda authored Dec 14, 2024
1 parent 56f9a43 commit 5294b28
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions BBDown.Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private static async Task<string> GetPlayJsonAsync(string aid, string cid, strin
paramBuilder.Append($"&cid={cid}&ep_id={epId}&platform=android&prefer_code_type={code}&qn={qn}");
if (isBiliPlus) paramBuilder.Append($"&ts={GetTimeStamp(true)}");

paramBuilder.Append("&s_locale=zh_SG");
string param = paramBuilder.ToString();
api += (isBiliPlus ? $"{param}&sign={GetSign(param, true)}" : param);

Expand Down
6 changes: 4 additions & 2 deletions BBDown.Core/Util/HTTPUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ private static string GetRandomUserAgent()

public static string UserAgent { get; set; } = GetRandomUserAgent();

public static async Task<string> GetWebSourceAsync(string url)
public static async Task<string> GetWebSourceAsync(string url, string? userAgent = null)
{
using var webRequest = new HttpRequestMessage(HttpMethod.Get, url);
webRequest.Headers.TryAddWithoutValidation("User-Agent", UserAgent);
webRequest.Headers.TryAddWithoutValidation("User-Agent", userAgent ?? UserAgent);
webRequest.Headers.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
webRequest.Headers.TryAddWithoutValidation("Cookie", (url.Contains("/ep") || url.Contains("/ss")) ? Config.COOKIE + ";CURRENT_FNVAL=4048;" : Config.COOKIE);
if (url.Contains("api.bilibili.com"))
webRequest.Headers.TryAddWithoutValidation("Referer", "https://www.bilibili.com/");
if (url.Contains("api.bilibili.tv"))
webRequest.Headers.TryAddWithoutValidation("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
webRequest.Headers.CacheControl = CacheControlHeaderValue.Parse("no-cache");
webRequest.Headers.Connection.Clear();

Expand Down
2 changes: 1 addition & 1 deletion BBDown/BBDownMuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static int MuxAV(bool useMp4box, string bvid, string videoPath, string au
if (episodeId != "") argsBuilder.Append($"-metadata album=\"{title}\" ");
if (pubTime != 0) argsBuilder.Append($"-metadata creation_time=\"{(DateTimeOffset.FromUnixTimeSeconds(pubTime).ToString("yyyy-MM-ddTHH:mm:ss.ffffffZ"))}\" ");
}
argsBuilder.Append("-c copy ");
argsBuilder.Append("-c:v copy -c:a copy ");
if (audioOnly && audioPath == "") argsBuilder.Append("-vn ");
if (subs != null) argsBuilder.Append("-c:s mov_text ");
// fix macOS hev1, see https://discussions.apple.com/thread/253081863?sortBy=rank
Expand Down
6 changes: 3 additions & 3 deletions BBDown/BBDownUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ public static async Task<bool> CheckLogin(string cookie)
private static partial Regex EpRegex();
[GeneratedRegex("/ss(\\d+)")]
private static partial Regex SsRegex();
[GeneratedRegex("space\\.bilibili\\.com/(\\d+)")]
[GeneratedRegex(@"space\.bilibili\.com/(\d+)")]
private static partial Regex UidRegex();
[GeneratedRegex("global\\.bilibili\\.com/play/\\d+/(\\d+)")]
[GeneratedRegex(@"\.bilibili\.tv\/\w+\/play\/\d+\/(\d+)")]
private static partial Regex GlobalEpRegex();
[GeneratedRegex("bangumi/media/(md\\d+)")]
private static partial Regex BangumiMdRegex();
[GeneratedRegex("window.__INITIAL_STATE__=([\\s\\S].*?);\\(function\\(\\)")]
[GeneratedRegex(@"window.__INITIAL_STATE__=([\s\S].*?);\(function\(\)")]
private static partial Regex StateRegex();
[GeneratedRegex("md(\\d+)")]
private static partial Regex MdRegex();
Expand Down
10 changes: 4 additions & 6 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ public static (Dictionary<string, byte> encodingPriority, Dictionary<string, int

public static async Task<(string fetchedAid, VInfo vInfo, string apiType)> GetVideoInfoAsync(MyOption myOption, string aidOri, string input)
{
Log("检测账号登录...");

// 加载认证信息
LoadCredentials(myOption);

// 检测是否登录了账号
bool is_login = await CheckLogin(Config.COOKIE);
if (!myOption.UseIntlApi && !myOption.UseTvApi && Config.AREA == "")
if (myOption is { UseIntlApi: false, UseTvApi: false } && Config.AREA == "")
{
if (!is_login)
Log("检测账号登录...");
if (!await CheckLogin(Config.COOKIE))
{
LogWarn("你尚未登录B站账号, 解析可能受到限制");
}
Expand Down Expand Up @@ -288,7 +286,7 @@ public static (Dictionary<string, byte> encodingPriority, Dictionary<string, int
Log("发布时间: " + FormatTimeStamp(pubTime, "yyyy-MM-dd HH:mm:ss zzz"));
}
var bvid = vInfo.PagesInfo.FirstOrDefault()?.bvid;
if (!string.IsNullOrEmpty(bvid))
if (!string.IsNullOrEmpty(bvid) && !myOption.UseIntlApi)
{
Log($"视频URL: https://www.bilibili.com/video/{bvid}/");
}
Expand Down

0 comments on commit 5294b28

Please sign in to comment.