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

fix av parsing #697

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
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
35 changes: 14 additions & 21 deletions BBDown/BBDownUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public static async Task<string> GetAvIdAsync(string input)
}
else if ((match = BangumiMdRegex().Match(input)).Success)
{
var mdId = match.Groups[1].Value;
avid = await GetAvIdAsync(mdId);
string mdId = match.Groups[1].Value;
string epId = await GetEpIdByMDAsync(mdId);
avid = $"ep:{epId}";
}
else
{
Expand All @@ -150,7 +151,7 @@ public static async Task<string> GetAvIdAsync(string input)
}
else if (input.StartsWith("ep"))
{
string epId = EpRegex2().Match(input).Groups[1].Value;
string epId = input[2..];
avid = $"ep:{epId}";
}
else if (input.StartsWith("ss"))
Expand Down Expand Up @@ -197,22 +198,22 @@ public static string FormatTime(int time, bool absolute = false)
/// </summary>
/// <param name="avid"></param>
/// <returns></returns>
public static async Task<string> FixAvidAsync(string avid)
private static async Task<string> FixAvidAsync(string avid)
{
if (!NumRegex().IsMatch(avid))
if (!avid.All(char.IsDigit))
return avid;
string api = $"https://www.bilibili.com/video/av{avid}/";
string location = await GetWebLocationAsync(api);
return location.Contains("/video/") ? avid : $"ep:{RedirectRegex().Match(location).Groups[1].Value}";
return location.Contains("/ep") ? $"ep:{EpRegex().Match(location).Groups[1].Value}" : avid;
}

public static string GetAidByBV(string bv)
private static string GetAidByBV(string bv)
{
// 能在本地就在本地
return Core.Util.BilibiliBvConverter.Decode(bv).ToString();
}

public static async Task<string> GetEpidBySSIdAsync(string ssid)
private static async Task<string> GetEpidBySSIdAsync(string ssid)
{
string api = $"https://api.bilibili.com/pugv/view/web/season?season_id={ssid}";
string json = await GetWebSourceAsync(api);
Expand All @@ -221,7 +222,7 @@ public static async Task<string> GetEpidBySSIdAsync(string ssid)
return epId;
}

public static async Task<string> GetEpIdByBangumiSSIdAsync(string ssId)
private static async Task<string> GetEpIdByBangumiSSIdAsync(string ssId)
{
string api = $"https://{Core.Config.EPHOST}/pgc/view/web/season?season_id={ssId}";
string json = await GetWebSourceAsync(api);
Expand All @@ -230,7 +231,7 @@ public static async Task<string> GetEpIdByBangumiSSIdAsync(string ssId)
return epId;
}

public static async Task<string> GetEpIdByMDAsync(string mdId)
private static async Task<string> GetEpIdByMDAsync(string mdId)
{
string api = $"https://api.bilibili.com/pgc/review/user?media_id={mdId}";
string json = await GetWebSourceAsync(api);
Expand Down Expand Up @@ -291,7 +292,7 @@ private static async Task RangeDownloadToTmpAsync(int id, string url, string tmp
/// <returns></returns>
private static string ReplaceUrl(string url)
{
if (McdnRegex().IsMatch(url))
if (url.Contains(".mcdn.bilivideo.cn:"))
{
LogDebug("对[*.mcdn.bilivideo.cn:xxx]域名不做处理");
return url;
Expand Down Expand Up @@ -430,7 +431,7 @@ private static List<Clip> GetAllClips(string url, long fileSize)
/// <param name="outputFilePath"></param>
public static void CombineMultipleFilesIntoSingleFile(string[] files, string outputFilePath)
{
if (files.Length == 0) return;
if (!files.Any()) return;
if (files.Length == 1)
{
FileInfo fi = new(files[0]);
Expand Down Expand Up @@ -493,7 +494,7 @@ private static async Task<long> GetFileSizeAsync(string url)
}

private static char[] InvalidChars = "34,60,62,124,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,58,42,63,92,47"
.Split(',').Select(s => (char)int.Parse(s)).ToArray();
.Split(',').Select(s => (char)byte.Parse(s)).ToArray();

public static string GetValidFileName(string input, string re = "_", bool filterSlash = false)
{
Expand Down Expand Up @@ -792,16 +793,8 @@ public static async Task<bool> CheckLogin(string cookie)
private static partial Regex BangumiMdRegex();
[GeneratedRegex("window.__INITIAL_STATE__=([\\s\\S].*?);\\(function\\(\\)")]
private static partial Regex StateRegex();
[GeneratedRegex("ep(\\d+)")]
private static partial Regex EpRegex2();
[GeneratedRegex("md(\\d+)")]
private static partial Regex MdRegex();
[GeneratedRegex("^\\d+$")]
private static partial Regex NumRegex();
[GeneratedRegex("ep(\\d+)")]
private static partial Regex RedirectRegex();
[GeneratedRegex("://.*mcdn\\.bilivideo\\.cn:\\d+")]
private static partial Regex McdnRegex();
[GeneratedRegex("(^|&)?(\\w+)=([^&]+)(&|$)?", RegexOptions.Compiled)]
private static partial Regex QueryRegex();
[GeneratedRegex("libavutil\\s+(\\d+)\\. +(\\d+)\\.")]
Expand Down