Skip to content

Commit

Permalink
Merge pull request #697 from My-Responsitories/fix
Browse files Browse the repository at this point in the history
fix av parsing #695
  • Loading branch information
nilaoda authored Aug 23, 2023
2 parents 92c3ba1 + 7a2ab5d commit e6e1e67
Showing 1 changed file with 14 additions and 21 deletions.
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

0 comments on commit e6e1e67

Please sign in to comment.