Skip to content

Commit

Permalink
Fix #855
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed May 12, 2024
1 parent baecdc2 commit ae2ce7f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static async Task<int> Main(params string[] args)
return 1;
}

if (commandLineResult.CommandResult.Command.Name.ToLower() != Path.GetFileNameWithoutExtension(Environment.ProcessPath)!.ToLower())
if (commandLineResult.CommandResult.Command.Name.ToLower() != Path.GetFileNameWithoutExtension(Environment.ProcessPath)!.ToLower() && Path.GetFileNameWithoutExtension(Environment.ProcessPath)!.ToLower() != "dotnet")
{
// 服务器模式需要完整的arg列表
if (commandLineResult.CommandResult.Command.Name.ToLower() == "serve")
Expand Down Expand Up @@ -332,7 +332,7 @@ public static async Task DownloadPagesAsync(MyOption myOption, VInfo vInfo, Dict
}
}

await DownloadPageAsync(p, myOption, vInfo, encodingPriority, dfnPriority, firstEncoding,
await DownloadPageAsync(p, myOption, vInfo, pagesInfo, encodingPriority, dfnPriority, firstEncoding,
downloadDanmaku, input, savePathFormat, lang, aidOri, apiType, relatedTask);

if (myOption.SaveArchivesToFile)
Expand All @@ -344,13 +344,12 @@ await DownloadPageAsync(p, myOption, vInfo, encodingPriority, dfnPriority, first
Log("任务完成");
}

private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vInfo, Dictionary<string, byte> encodingPriority, Dictionary<string, int> dfnPriority,
private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vInfo, List<Page> selectedPagesInfo, Dictionary<string, byte> encodingPriority, Dictionary<string, int> dfnPriority,
string? firstEncoding, bool downloadDanmaku, string input, string savePathFormat, string lang, string aidOri, string apiType, DownloadTask? relatedTask = null)
{
List<Page> pagesInfo = vInfo.PagesInfo;
string desc = string.IsNullOrEmpty(p.desc) ? vInfo.Desc : p.desc;
bool bangumi = vInfo.IsBangumi;
var pagesCount = pagesInfo.Count;
var pagesCount = selectedPagesInfo.Count;
List<Subtitle> subtitleInfo = new();
string title = vInfo.Title;
string pic = vInfo.Pic;
Expand Down Expand Up @@ -448,13 +447,13 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
{
if (parsedResult.VideoTracks.Count == 0)
{
LogError("没有找到符合要求的视频流");
if (!myOption.AudioOnly) return;
LogWarn("没有找到符合要求的视频流");
if (myOption.VideoOnly) return;
}
if (parsedResult.AudioTracks.Count == 0)
{
LogError("没有找到符合要求的音频流");
if (!myOption.VideoOnly) return;
LogWarn("没有找到符合要求的音频流");
if (myOption.AudioOnly) return;
}

if (myOption.AudioOnly)
Expand Down Expand Up @@ -638,7 +637,7 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
if (p.points.Any()) File.Delete(Path.Combine(Path.GetDirectoryName(string.IsNullOrEmpty(videoPath) ? audioPath : videoPath)!, "chapters"));
foreach (var s in subtitleInfo) File.Delete(s.path);
foreach (var a in audioMaterial) File.Delete(a.path);
if (pagesInfo.Count == 1 || p.index == pagesInfo.Last().index || p.aid != pagesInfo.Last().aid)
if (selectedPagesInfo.Count == 1 || p.index == selectedPagesInfo.Last().index || p.aid != selectedPagesInfo.Last().aid)
File.Delete(coverPath);
if (Directory.Exists(p.aid) && Directory.GetFiles(p.aid).Length == 0) Directory.Delete(p.aid, true);
}
Expand Down Expand Up @@ -685,7 +684,7 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
if (File.Exists(savePath) && new FileInfo(savePath).Length != 0)
{
Log($"{savePath}已存在, 跳过下载...");
if (pagesInfo.Count == 1 && Directory.Exists(p.aid))
if (selectedPagesInfo.Count == 1 && Directory.Exists(p.aid))
{
Directory.Delete(p.aid, true);
}
Expand Down Expand Up @@ -726,7 +725,7 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
foreach (var s in subtitleInfo) File.Delete(s.path);
foreach (var a in audioMaterial) File.Delete(a.path);
if (p.points.Any()) File.Delete(Path.Combine(Path.GetDirectoryName(string.IsNullOrEmpty(videoPath) ? audioPath : videoPath)!, "chapters"));
if (pagesInfo.Count == 1 || p.index == pagesInfo.Last().index || p.aid != pagesInfo.Last().aid)
if (selectedPagesInfo.Count == 1 || p.index == selectedPagesInfo.Last().index || p.aid != selectedPagesInfo.Last().aid)
File.Delete(coverPath);
if (Directory.Exists(p.aid) && Directory.GetFiles(p.aid).Length == 0) Directory.Delete(p.aid, true);
}
Expand Down

0 comments on commit ae2ce7f

Please sign in to comment.