Skip to content

Commit c5d97c2

Browse files
authored
元数据写入视频URL (#958)
1 parent 5423f19 commit c5d97c2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

BBDown/BBDownMuxer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static string EscapeString(string str)
4444
return string.IsNullOrEmpty(str) ? str : str.Replace("\"", "'").Replace("\\", "\\\\");
4545
}
4646

47-
private static int MuxByMp4box(string videoPath, string audioPath, string outPath, string desc, string title, string author, string episodeId, string pic, string lang, List<Subtitle>? subs, bool audioOnly, bool videoOnly, List<ViewPoint>? points)
47+
private static int MuxByMp4box(string url, string videoPath, string audioPath, string outPath, string desc, string title, string author, string episodeId, string pic, string lang, List<Subtitle>? subs, bool audioOnly, bool videoOnly, List<ViewPoint>? points)
4848
{
4949
StringBuilder inputArg = new();
5050
StringBuilder metaArg = new();
@@ -73,7 +73,8 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
7373
metaArg.Append($":album=\"{title}\":title=\"{episodeId}\"");
7474
else
7575
metaArg.Append($":title=\"{title}\"");
76-
metaArg.Append($":comment=\"{desc}\"");
76+
metaArg.Append($":sdesc=\"{desc}\"");
77+
metaArg.Append($":comment=\"{url}\"");
7778
metaArg.Append($":artist=\"{author}\"");
7879

7980
if (subs != null)
@@ -90,12 +91,12 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
9091
}
9192

9293
//----分析完毕
93-
var arguments = (Config.DEBUG_LOG ? " -v " : "") + inputArg + (metaArg.ToString() == "" ? "" : " -itags tool=" + metaArg.ToString()) + $" -new -- \"{outPath}\"";
94+
var arguments = (Config.DEBUG_LOG ? " -v " : "") + inputArg + (metaArg.ToString() == "" ? "" : " -itags tool=" + metaArg) + $" -new -- \"{outPath}\"";
9495
LogDebug("mp4box命令: {0}", arguments);
9596
return RunExe(MP4BOX, arguments, MP4BOX != "mp4box");
9697
}
9798

98-
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)
99+
public static int MuxAV(bool useMp4box, string bvid, 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)
99100
{
100101
if (audioOnly && audioPath != "")
101102
videoPath = "";
@@ -104,10 +105,11 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
104105
desc = EscapeString(desc);
105106
title = EscapeString(title);
106107
episodeId = EscapeString(episodeId);
108+
var url = $"https://www.bilibili.com/video/{bvid}/";
107109

108110
if (useMp4box)
109111
{
110-
return MuxByMp4box(videoPath, audioPath, outPath, desc, title, author, episodeId, pic, lang, subs, audioOnly, videoOnly, points);
112+
return MuxByMp4box(url, videoPath, audioPath, outPath, desc, title, author, episodeId, pic, lang, subs, audioOnly, videoOnly, points);
111113
}
112114

113115
if (outPath.Contains('/') && ! Directory.Exists(Path.GetDirectoryName(outPath)))
@@ -179,6 +181,7 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
179181
argsBuilder.Append(metaArg);
180182
if (!simplyMux) {
181183
argsBuilder.Append($"-metadata title=\"{(episodeId == "" ? title : episodeId)}\" ");
184+
argsBuilder.Append($"-metadata comment=\"{url}\" ");
182185
if (lang != "") argsBuilder.Append($"-metadata:s:a:0 language={lang} ");
183186
if (!string.IsNullOrWhiteSpace(desc)) argsBuilder.Append($"-metadata description=\"{desc}\" ");
184187
if (!string.IsNullOrEmpty(author)) argsBuilder.Append($"-metadata artist=\"{author}\" ");

BBDown/Program.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public static (Dictionary<string, byte> encodingPriority, Dictionary<string, int
244244

245245
Log("获取aid...");
246246
aidOri = await GetAvIdAsync(input);
247-
Log("获取aid结束: " + aidOri);
247+
Log($"获取aid结束: {aidOri}");
248248

249249
if (string.IsNullOrEmpty(aidOri))
250250
{
@@ -287,6 +287,11 @@ public static (Dictionary<string, byte> encodingPriority, Dictionary<string, int
287287
{
288288
Log("发布时间: " + FormatTimeStamp(pubTime, "yyyy-MM-dd HH:mm:ss zzz"));
289289
}
290+
var bvid = vInfo.PagesInfo.FirstOrDefault()?.bvid;
291+
if (!string.IsNullOrEmpty(bvid))
292+
{
293+
Log($"视频URL: https://www.bilibili.com/video/{bvid}/");
294+
}
290295
var mid = vInfo.PagesInfo.FirstOrDefault(p => !string.IsNullOrEmpty(p.ownerMid))?.ownerMid;
291296
if (!string.IsNullOrEmpty(mid))
292297
{
@@ -664,7 +669,7 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
664669
Log($"开始合并音视频{(subtitleInfo.Any() ? "和字幕" : "")}...");
665670
if (myOption.AudioOnly)
666671
savePath = savePath[..^4] + ".m4a";
667-
int code = BBDownMuxer.MuxAV(myOption.UseMP4box, videoPath, audioPath, audioMaterial, savePath,
672+
int code = BBDownMuxer.MuxAV(myOption.UseMP4box, p.bvid, videoPath, audioPath, audioMaterial, savePath,
668673
desc,
669674
title,
670675
p.ownerName ?? "",
@@ -753,7 +758,7 @@ private static async Task DownloadPageAsync(Page p, MyOption myOption, VInfo vIn
753758
Log($"开始混流视频{(subtitleInfo.Any() ? "和字幕" : "")}...");
754759
if (myOption.AudioOnly)
755760
savePath = savePath[..^4] + ".m4a";
756-
int code = BBDownMuxer.MuxAV(false, videoPath, "", audioMaterial, savePath,
761+
int code = BBDownMuxer.MuxAV(false, p.bvid, videoPath, "", audioMaterial, savePath,
757762
desc,
758763
title,
759764
p.ownerName ?? "",

0 commit comments

Comments
 (0)