Skip to content

Commit

Permalink
Merge pull request #745 from AdiEcho/master
Browse files Browse the repository at this point in the history
fix: close #742 增加精简混流参数,和其他优化项
  • Loading branch information
nilaoda committed Oct 21, 2023
2 parents 6f310f3 + ded1ef7 commit cd34fa1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
16 changes: 9 additions & 7 deletions BBDown/BBDownMuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
return RunExe(MP4BOX, arguments, MP4BOX != "mp4box");
}

public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List<AudioMaterial> audioMaterial, string outPath, string desc = "", string title = "", string author = "", string episodeId = "", string pic = "", string lang = "", List<Subtitle>? subs = null, bool audioOnly = false, bool videoOnly = false, List<ViewPoint>? points = null, long pubTime = 0)
public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List<AudioMaterial> audioMaterial, string outPath, string desc = "", string title = "", string author = "", string episodeId = "", string pic = "", string lang = "", List<Subtitle>? subs = null, bool audioOnly = false, bool videoOnly = false, List<ViewPoint>? points = null, long pubTime = 0, bool simplyMux = false)
{
if (audioOnly && audioPath != "")
videoPath = "";
Expand Down Expand Up @@ -177,12 +177,14 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
argsBuilder.Append($"-loglevel {(Config.DEBUG_LOG ? "verbose" : "warning")} -y ");
argsBuilder.Append(inputArg);
argsBuilder.Append(metaArg);
argsBuilder.Append($"-metadata title=\"{(episodeId == "" ? title : episodeId)}\" ");
if (lang != "") argsBuilder.Append($"-metadata:s:a:0 language={lang} ");
if (!string.IsNullOrWhiteSpace(desc)) argsBuilder.Append($"-metadata description=\"{desc}\" ");
if (!string.IsNullOrEmpty(author)) argsBuilder.Append($"-metadata artist=\"{author}\" ");
if (episodeId != "") argsBuilder.Append($"-metadata album=\"{title}\" ");
if (pubTime != 0) argsBuilder.Append($"-metadata creation_time=\"{(DateTimeOffset.FromUnixTimeSeconds(pubTime).ToString("yyyy-MM-ddTHH:mm:ss.ffffffZ"))}\" ");
if (!simplyMux) {
argsBuilder.Append($"-metadata title=\"{(episodeId == "" ? title : episodeId)}\" ");
if (lang != "") argsBuilder.Append($"-metadata:s:a:0 language={lang} ");
if (!string.IsNullOrWhiteSpace(desc)) argsBuilder.Append($"-metadata description=\"{desc}\" ");
if (!string.IsNullOrEmpty(author)) argsBuilder.Append($"-metadata artist=\"{author}\" ");
if (episodeId != "") argsBuilder.Append($"-metadata album=\"{title}\" ");
if (pubTime != 0) argsBuilder.Append($"-metadata creation_time=\"{(DateTimeOffset.FromUnixTimeSeconds(pubTime).ToString("yyyy-MM-ddTHH:mm:ss.ffffffZ"))}\" ");
}
argsBuilder.Append("-c copy ");
if (audioOnly && audioPath == "") argsBuilder.Append("-vn ");
if (subs != null) argsBuilder.Append("-c:s mov_text ");
Expand Down
2 changes: 2 additions & 0 deletions BBDown/CommandLineInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class CommandLineInvoker
private readonly static Option<string> Aria2cArgs = new(new string[] { "--aria2c-args" }, "调用aria2c的附加参数(默认参数包含\"-x16 -s16 -j16 -k 5M\", 使用时注意字符串转义)");
private readonly static Option<bool> MultiThread = new(new string[] { "--multi-thread", "-mt" }, "使用多线程下载(默认开启)");
private readonly static Option<string> SelectPage = new(new string[] { "--select-page", "-p" }, "选择指定分p或分p范围: (-p 8 或 -p 1,2 或 -p 3-5 或 -p ALL 或 -p LAST 或 -p 3,5,LATEST)");
private readonly static Option<bool> SimplyMux = new(new string[] { "--simply-mux" }, "精简混流,不增加描述、作者等信息");
private readonly static Option<bool> AudioOnly = new(new string[] { "--audio-only" }, "仅下载音频");
private readonly static Option<bool> VideoOnly = new(new string[] { "--video-only" }, "仅下载视频");
private readonly static Option<bool> DanmakuOnly = new(new string[] { "--danmaku-only" }, "仅下载弹幕");
Expand Down Expand Up @@ -88,6 +89,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
if (bindingContext.ParseResult.HasOption(Interactive)) option.Interactive = bindingContext.ParseResult.GetValueForOption(Interactive)!;
if (bindingContext.ParseResult.HasOption(HideStreams)) option.HideStreams = bindingContext.ParseResult.GetValueForOption(HideStreams)!;
if (bindingContext.ParseResult.HasOption(MultiThread)) option.MultiThread = bindingContext.ParseResult.GetValueForOption(MultiThread)!;
if (bindingContext.ParseResult.HasOption(SimplyMux)) option.SimplyMux = bindingContext.ParseResult.GetValueForOption(SimplyMux)!;
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)!;
Expand Down
1 change: 1 addition & 0 deletions BBDown/MyOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class MyOption
public bool Interactive { get; set; }
public bool HideStreams { get; set; }
public bool MultiThread { get; set; } = true;
public bool SimplyMux { get; set; } = false;
public bool VideoOnly { get; set; }
public bool AudioOnly { get; set; }
public bool DanmakuOnly { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private static async Task DoWorkAsync(MyOption myOption)
(pagesCount > 1 || (bangumi && !vInfo.IsBangumiEnd)) ? p.title : "",
File.Exists(coverPath) ? coverPath : "",
lang,
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime);
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime, myOption.SimplyMux);
if (code != 0 || !File.Exists(savePath) || new FileInfo(savePath).Length == 0)
{
LogError("合并失败"); continue;
Expand Down Expand Up @@ -634,7 +634,7 @@ private static async Task DoWorkAsync(MyOption myOption)
(pagesCount > 1 || (bangumi && !vInfo.IsBangumiEnd)) ? p.title : "",
File.Exists(coverPath) ? coverPath : "",
lang,
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime);
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime, myOption.SimplyMux);
if (code != 0 || !File.Exists(savePath) || new FileInfo(savePath).Length == 0)
{
LogError("合并失败"); continue;
Expand Down Expand Up @@ -713,7 +713,7 @@ private static string FormatSavePath(string savePathFormat, string title, Video?
{
"videoTitle" => GetValidFileName(title, filterSlash: true).Trim().TrimEnd('.').Trim(),
"pageNumber" => p.index.ToString(),
"pageNumberWithZero" => p.index.ToString().PadLeft((int)Math.Log10(pagesCount) + 1, '0'),
"pageNumberWithZero" => p.index.ToString().PadLeft(pagesCount.ToString().Length, '0'),
"pageTitle" => GetValidFileName(p.title, filterSlash: true).Trim().TrimEnd('.').Trim(),
"bvid" => p.bvid,
"aid" => p.aid,
Expand Down

0 comments on commit cd34fa1

Please sign in to comment.