Skip to content

Commit b713de2

Browse files
authored
add: support placeholder
- <videoTitle> - <pageNumber> - <pageNumberWithZero> - <pageTitle> - <bvid> - <aid> - <cid> - <ownerName> - <ownerMid>
1 parent 523d597 commit b713de2

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

BBDown/BBDownMuxer.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
9696
return RunExe(MP4BOX, arguments, MP4BOX != "mp4box");
9797
}
9898

99-
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, MyOption myOption = null)
99+
public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List<AudioMaterial> audioMaterial, string outPath,
100+
string desc = "", string title = "", string author = "", string episodeId = "", string pic = "", string lang = "", List<Subtitle>? subs = null,
101+
bool audioOnly = false, bool videoOnly = false, List<ViewPoint>? points = null,
102+
long pubTime = 0, bool simplyMux = false, MyOption myOption = null,Page p = null,int pagesCount = 0)
100103
{
101104
if (audioOnly && audioPath != "")
102105
videoPath = "";
@@ -195,7 +198,7 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
195198
if (match.Success)
196199
{
197200
string key = match.Groups[1].Value;
198-
string value = GetValueForReplacement(key, metadata);
201+
string value = FormatValue(GetValueForReplacement(key, metadata),title,p,pagesCount);
199202
if (!string.IsNullOrEmpty(value))
200203
{
201204
argsBuilder.Replace($"{key}={match.Groups[2].Value}", $"{key}=\"{value}\" ");
@@ -207,10 +210,10 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
207210
foreach (var keyValuePair in keyValuePairs)
208211
{
209212
string[] parts = keyValuePair.Split('=');
210-
if (parts.Length == 2)
213+
if (parts.Length == 2)
211214
{
212215
string key = parts[0];
213-
string value = parts[1];
216+
string value = FormatValue(parts[1], title, p, pagesCount);
214217
argsBuilder.Append($"-metadata {key}=\"{value}\" ");
215218
}
216219
}
@@ -262,5 +265,28 @@ private static string GetValueForReplacement(string key, string input)
262265
return string.Empty;
263266
}
264267
}
268+
269+
private static string FormatValue(string value,string title,Page p,int pagesCount) {
270+
var regex = Program.InfoRegex();
271+
foreach (Match m in regex.Matches(value).Cast<Match>())
272+
{
273+
var key = m.Groups[1].Value;
274+
var v = key switch
275+
{
276+
"videoTitle" => Program.GetValidFileName(title, filterSlash: true).Trim().TrimEnd('.').Trim(),
277+
"pageNumber" => p.index.ToString(),
278+
"pageNumberWithZero" => p.index.ToString().PadLeft(pagesCount.ToString().Length, '0'),
279+
"pageTitle" => Program.GetValidFileName(p.title, filterSlash: true).Trim().TrimEnd('.').Trim(),
280+
"bvid" => p.bvid,
281+
"aid" => p.aid,
282+
"cid" => p.cid,
283+
"ownerName" => p.ownerName == null ? "" : Program.GetValidFileName(p.ownerName, filterSlash: true).Trim().TrimEnd('.').Trim(),
284+
"ownerMid" => p.ownerMid ?? "",
285+
_ => $"<{key}>"
286+
};
287+
value = value.Replace(m.Value, v);
288+
}
289+
return value;
290+
}
265291
}
266292
}

BBDown/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
626626
(pagesCount > 1 || (bangumi && !vInfo.IsBangumiEnd)) ? p.title : "",
627627
File.Exists(coverPath) ? coverPath : "",
628628
lang,
629-
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime, myOption.SimplyMux, myOption);
629+
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points,
630+
p.pubTime, myOption.SimplyMux, myOption, p, pagesCount);
630631
if (code != 0 || !File.Exists(savePath) || new FileInfo(savePath).Length == 0)
631632
{
632633
LogError("合并失败"); return;
@@ -715,7 +716,8 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
715716
(pagesCount > 1 || (bangumi && !vInfo.IsBangumiEnd)) ? p.title : "",
716717
File.Exists(coverPath) ? coverPath : "",
717718
lang,
718-
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime, myOption.SimplyMux, myOption);
719+
subtitleInfo, myOption.AudioOnly, myOption.VideoOnly, p.points, p.pubTime,
720+
myOption.SimplyMux, myOption, p, pagesCount);
719721
if (code != 0 || !File.Exists(savePath) || new FileInfo(savePath).Length == 0)
720722
{
721723
LogError("合并失败"); return;
@@ -843,6 +845,6 @@ private static string FormatSavePath(string savePathFormat, string title, Video?
843845
}
844846

845847
[GeneratedRegex("<([\\w:]+?)>")]
846-
private static partial Regex InfoRegex();
848+
public static partial Regex InfoRegex();
847849
}
848850
}

0 commit comments

Comments
 (0)