diff --git a/BBDown/CommandLineInvoker.cs b/BBDown/CommandLineInvoker.cs index 1e0df8d7e..4b468b350 100644 --- a/BBDown/CommandLineInvoker.cs +++ b/BBDown/CommandLineInvoker.cs @@ -28,6 +28,7 @@ internal class CommandLineInvoker private readonly static Option SelectPage = new(new string[] { "--select-page", "-p" }, "选择指定分p或分p范围: (-p 8 或 -p 1,2 或 -p 3-5 或 -p ALL 或 -p LAST)"); private readonly static Option AudioOnly = new(new string[] { "--audio-only" }, "仅下载音频"); private readonly static Option VideoOnly = new(new string[] { "--video-only" }, "仅下载视频"); + private readonly static Option DanmakuOnly = new(new string[] { "--danmaku-only" }, "仅下载弹幕"); private readonly static Option SubOnly = new(new string[] { "--sub-only" }, "仅下载字幕"); private readonly static Option Debug = new(new string[] { "--debug" }, "输出调试日志"); private readonly static Option SkipMux = new(new string[] { "--skip-mux" }, "跳过混流步骤"); @@ -83,6 +84,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext) if (bindingContext.ParseResult.HasOption(MultiThread)) option.MultiThread = bindingContext.ParseResult.GetValueForOption(MultiThread)!; if (bindingContext.ParseResult.HasOption(VideoOnly)) option.VideoOnly = bindingContext.ParseResult.GetValueForOption(VideoOnly)!; if (bindingContext.ParseResult.HasOption(AudioOnly)) option.AudioOnly = bindingContext.ParseResult.GetValueForOption(AudioOnly)!; + if (bindingContext.ParseResult.HasOption(DanmakuOnly)) option.DanmakuOnly = bindingContext.ParseResult.GetValueForOption(DanmakuOnly)!; if (bindingContext.ParseResult.HasOption(SubOnly)) option.SubOnly = bindingContext.ParseResult.GetValueForOption(SubOnly)!; if (bindingContext.ParseResult.HasOption(Debug)) option.Debug = bindingContext.ParseResult.GetValueForOption(Debug)!; if (bindingContext.ParseResult.HasOption(SkipMux)) option.SkipMux = bindingContext.ParseResult.GetValueForOption(SkipMux)!; @@ -138,6 +140,7 @@ public static RootCommand GetRootCommand(Func action) MultiThread, VideoOnly, AudioOnly, + DanmakuOnly, SubOnly, Debug, SkipMux, diff --git a/BBDown/Program.cs b/BBDown/Program.cs index bfaee78e1..68e3329cb 100644 --- a/BBDown/Program.cs +++ b/BBDown/Program.cs @@ -184,12 +184,13 @@ private static async Task DoWorkAsync(MyOption myOption) bool multiThread = myOption.MultiThread; bool audioOnly = myOption.AudioOnly; bool videoOnly = myOption.VideoOnly; + bool danmakuOnly = myOption.DanmakuOnly; bool subOnly = myOption.SubOnly; bool skipMux = myOption.SkipMux; bool skipSubtitle = myOption.SkipSubtitle; bool skipCover = myOption.SkipCover; bool forceHttp = myOption.ForceHttp; - bool downloadDanmaku = myOption.DownloadDanmaku; + bool downloadDanmaku = myOption.DownloadDanmaku || danmakuOnly; bool skipAi = myOption.SkipAi; bool bandwithAscending = myOption.BandwithAscending; bool showAll = myOption.ShowAll; @@ -486,7 +487,7 @@ private static async Task DoWorkAsync(MyOption myOption) { Directory.CreateDirectory(p.aid); } - if (!skipCover && !subOnly && !File.Exists(coverPath)) + if (!skipCover && !subOnly && !File.Exists(coverPath) && !danmakuOnly) { Log("下载封面..."); var cover = pic == "" ? p.cover : pic; @@ -499,7 +500,7 @@ private static async Task DoWorkAsync(MyOption myOption) } } - if (!skipSubtitle) + if (!skipSubtitle && !danmakuOnly) { LogDebug("获取字幕..."); subtitleInfo = await SubUtil.GetSubtitlesAsync(p.aid, p.cid, p.epid, p.index, intlApi); @@ -590,6 +591,39 @@ private static async Task DoWorkAsync(MyOption myOption) } } if (infoMode) continue; + + LogDebug("Format Before: " + savePathFormat); + savePath = FormatSavePath(savePathFormat, title, videoTracks.ElementAtOrDefault(vIndex), audioTracks.ElementAtOrDefault(aIndex), p, pagesCount, tvApi, appApi, intlApi); + LogDebug("Format After: " + savePath); + + if (downloadDanmaku) + { + var danmakuXmlPath = savePath[..savePath.LastIndexOf('.')] + ".xml"; + var danmakuAssPath = savePath[..savePath.LastIndexOf('.')] + ".ass"; + Log("正在下载弹幕Xml文件"); + string danmakuUrl = "https://comment.bilibili.com/" + p.cid + ".xml"; + await DownloadFile(danmakuUrl, danmakuXmlPath, false, aria2cArgs); + var danmakus = DanmakuUtil.ParseXml(danmakuXmlPath); + if (danmakus != null) + { + Log("正在保存弹幕Ass文件..."); + await DanmakuUtil.SaveAsAssAsync(danmakus, danmakuAssPath); + } + else + { + Log("弹幕Xml解析失败, 删除Xml..."); + File.Delete(danmakuXmlPath); + } + if (danmakuOnly) + { + if (Directory.Exists(p.aid)) + { + Directory.Delete(p.aid); + } + continue; + } + } + if (interactMode && !hideStreams && !selected) { if (videoTracks.Count > 0) @@ -662,30 +696,6 @@ private static async Task DoWorkAsync(MyOption myOption) } } - LogDebug("Format Before: " + savePathFormat); - savePath = FormatSavePath(savePathFormat, title, videoTracks.ElementAtOrDefault(vIndex), audioTracks.ElementAtOrDefault(aIndex), p, pagesCount, tvApi, appApi, intlApi); - LogDebug("Format After: " + savePath); - - if (downloadDanmaku) - { - var danmakuXmlPath = savePath[..savePath.LastIndexOf('.')] + ".xml"; - var danmakuAssPath = savePath[..savePath.LastIndexOf('.')] + ".ass"; - Log("正在下载弹幕Xml文件"); - string danmakuUrl = "https://comment.bilibili.com/" + p.cid + ".xml"; - await DownloadFile(danmakuUrl, danmakuXmlPath, false, aria2cArgs); - var danmakus = DanmakuUtil.ParseXml(danmakuXmlPath); - if (danmakus != null) - { - Log("正在保存弹幕Ass文件..."); - await DanmakuUtil.SaveAsAssAsync(danmakus, danmakuAssPath); - } - else - { - Log("弹幕Xml解析失败, 删除Xml..."); - File.Delete(danmakuXmlPath); - } - } - if (videoTracks.Count > 0) {