From bd1a6d06f90628fbbe6c6596e4c894fdeb19ae6c Mon Sep 17 00:00:00 2001 From: nilaoda Date: Fri, 26 May 2023 16:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=85=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=B0=81=E9=9D=A2=20#408?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBDown/CommandLineInvoker.cs | 3 +++ BBDown/MyOption.cs | 2 ++ BBDown/Program.cs | 35 ++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/BBDown/CommandLineInvoker.cs b/BBDown/CommandLineInvoker.cs index 4b468b350..da841a1e3 100644 --- a/BBDown/CommandLineInvoker.cs +++ b/BBDown/CommandLineInvoker.cs @@ -29,6 +29,7 @@ internal class CommandLineInvoker 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 CoverOnly = new(new string[] { "--cover-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" }, "跳过混流步骤"); @@ -85,6 +86,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext) 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(CoverOnly)) option.CoverOnly = bindingContext.ParseResult.GetValueForOption(CoverOnly)!; 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)!; @@ -142,6 +144,7 @@ public static RootCommand GetRootCommand(Func action) AudioOnly, DanmakuOnly, SubOnly, + CoverOnly, Debug, SkipMux, SkipSubtitle, diff --git a/BBDown/MyOption.cs b/BBDown/MyOption.cs index e8629bb2b..4f4765803 100644 --- a/BBDown/MyOption.cs +++ b/BBDown/MyOption.cs @@ -23,6 +23,8 @@ internal class MyOption public bool MultiThread { get; set; } = true; public bool VideoOnly { get; set; } public bool AudioOnly { get; set; } + public bool DanmakuOnly { get; set; } + public bool CoverOnly { get; set; } public bool SubOnly { get; set; } public bool Debug { get; set; } public bool SkipMux { get; set; } diff --git a/BBDown/Program.cs b/BBDown/Program.cs index f2182a336..4d21cae98 100644 --- a/BBDown/Program.cs +++ b/BBDown/Program.cs @@ -185,6 +185,7 @@ private static async Task DoWorkAsync(MyOption myOption) bool audioOnly = myOption.AudioOnly; bool videoOnly = myOption.VideoOnly; bool danmakuOnly = myOption.DanmakuOnly; + bool coverOnly = myOption.CoverOnly; bool subOnly = myOption.SubOnly; bool skipMux = myOption.SkipMux; bool skipSubtitle = myOption.SkipSubtitle; @@ -487,20 +488,12 @@ private static async Task DoWorkAsync(MyOption myOption) { Directory.CreateDirectory(p.aid); } - if (!skipCover && !subOnly && !File.Exists(coverPath) && !danmakuOnly) + if (!skipCover && !subOnly && !File.Exists(coverPath) && !danmakuOnly && !coverOnly) { - Log("下载封面..."); - var cover = pic == "" ? p.cover : pic; - if (cover != null) - { - LogDebug("下载:{0}", cover); - await using var response = await HTTPUtil.AppHttpClient.GetStreamAsync(cover); - await using var fs = new FileStream(coverPath, FileMode.Create); - await response.CopyToAsync(fs); - } + await DownloadCoverAsync(pic, p, coverPath); } - if (!skipSubtitle && !danmakuOnly) + if (!skipSubtitle && !danmakuOnly && !coverOnly) { LogDebug("获取字幕..."); subtitleInfo = await SubUtil.GetSubtitlesAsync(p.aid, p.cid, p.epid, p.index, intlApi); @@ -624,6 +617,13 @@ private static async Task DoWorkAsync(MyOption myOption) } } + if (coverOnly) + { + var newCoverPath = savePath[..savePath.LastIndexOf('.')] + Path.GetExtension(pic); + await DownloadCoverAsync(pic, p, newCoverPath); + continue; + } + if (interactMode && !hideStreams && !selected) { if (videoTracks.Count > 0) @@ -946,6 +946,19 @@ private static async Task DoWorkAsync(MyOption myOption) } } + private static async Task DownloadCoverAsync(string pic, Page p, string coverPath) + { + Log("下载封面..."); + var cover = pic == "" ? p.cover : pic; + if (cover != null) + { + LogDebug("下载:{0}", cover); + await using var response = await HTTPUtil.AppHttpClient.GetStreamAsync(cover); + await using var fs = new FileStream(coverPath, FileMode.Create); + await response.CopyToAsync(fs); + } + } + private static List