Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化课程和番剧 EP/SS ID 解析,提升用户体验 #919

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions BBDown/BBDownUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public static async Task<string> GetAvIdAsync(string input)
string epId = await GetEpIdByBangumiSSIdAsync(SsRegex().Match(input).Groups[1].Value);
avid = $"ep:{epId}";
}
else if (input.Contains("/medialist/") && input.Contains("business_id=") && input.Contains("business=space_collection")) //列表类型是合集
else if (input.Contains("/medialist/") && input.Contains("business_id=") && input.Contains("business=space_collection")) // 列表类型是合集
{
string bizId = GetQueryString("business_id", input);
avid = $"listBizId:{bizId}";
}
else if (input.Contains("/medialist/") && input.Contains("business_id=") && input.Contains("business=space_series")) //列表类型是系列
else if (input.Contains("/medialist/") && input.Contains("business_id=") && input.Contains("business=space_series")) // 列表类型是系列
{
string bizId = GetQueryString("business_id", input);
avid = $"seriesBizId:{bizId}";
Expand Down Expand Up @@ -145,10 +145,23 @@ public static async Task<string> GetAvIdAsync(string input)
{
avid = GetAidByBV(input[3..]);
}
else if (input.ToLower().StartsWith("av")) //av
else if (input.ToLower().StartsWith("av")) // av
{
avid = input.ToLower()[2..];
}
else if (input.StartsWith("cheese/")) // cheese/(ep|ss)\d+ 格式
lc6464 marked this conversation as resolved.
Show resolved Hide resolved
{
string epId = "";
if (input.Contains("/ep"))
{
epId = EpRegex().Match(input).Groups[1].Value;
}
else if (input.Contains("/ss"))
{
epId = await GetEpidBySSIdAsync(SsRegex().Match(input).Groups[1].Value);
}
avid = $"cheese:{epId}";
}
else if (input.StartsWith("ep"))
{
string epId = input[2..];
Expand Down
38 changes: 32 additions & 6 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,21 @@ 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("检测账号登录...");
lc6464 marked this conversation as resolved.
Show resolved Hide resolved

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

// 检测是否登录了账号
bool is_login = await CheckLogin(Config.COOKIE);
// 检测是否登录了账号
lc6464 marked this conversation as resolved.
Show resolved Hide resolved
bool is_login = await CheckLogin(Config.COOKIE);
lc6464 marked this conversation as resolved.
Show resolved Hide resolved
if (!myOption.UseIntlApi && !myOption.UseTvApi && Config.AREA == "")
{
Log("检测账号登录...");
if (!is_login)
{
LogWarn("你尚未登录B站账号, 解析可能受到限制");
}
}

lc6464 marked this conversation as resolved.
Show resolved Hide resolved
Log("获取aid...");
aidOri = await GetAvIdAsync(input);
Log("获取aid结束: " + aidOri);
Expand All @@ -251,7 +252,32 @@ public static (Dictionary<string, byte> encodingPriority, Dictionary<string, int

Log("获取视频信息...");
IFetcher fetcher = FetcherFactory.CreateFetcher(aidOri, myOption.UseIntlApi);
var vInfo = await fetcher.FetchAsync(aidOri);
VInfo? vInfo = null;

// 只输入 EP/SS 时优先按番剧查找,如果找不到则尝试按课程查找
try
{
vInfo = await fetcher.FetchAsync(aidOri);
}
catch (KeyNotFoundException e)
{
if (e.Message != "Arg_KeyNotFound") throw; // 错误消息不符合预期,抛出异常
if (aidOri.StartsWith("cheese:")) throw; // 已经按课程查找过,不再重复尝试

LogWarn("未找到此 EP/SS 对应番剧信息, 正在尝试按课程查找。");

aidOri = aidOri.Replace("ep", "cheese");
Log("新的 aid: " + aidOri);

if (string.IsNullOrEmpty(aidOri)) {
throw new Exception("输入有误");
}

Log("获取视频信息...");
fetcher = FetcherFactory.CreateFetcher(aidOri, myOption.UseIntlApi);
vInfo = await fetcher.FetchAsync(aidOri);
}

string title = vInfo.Title;
long pubTime = vInfo.PubTime;
LogColor("视频标题: " + title);
Expand Down