Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

元数据写入视频URL #958

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions BBDown/BBDownMuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static string EscapeString(string str)
return string.IsNullOrEmpty(str) ? str : str.Replace("\"", "'").Replace("\\", "\\\\");
}

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)
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)
{
StringBuilder inputArg = new();
StringBuilder metaArg = new();
Expand Down Expand Up @@ -73,7 +73,8 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
metaArg.Append($":album=\"{title}\":title=\"{episodeId}\"");
else
metaArg.Append($":title=\"{title}\"");
metaArg.Append($":comment=\"{desc}\"");
metaArg.Append($":sdesc=\"{desc}\"");
metaArg.Append($":comment=\"{url}\"");
metaArg.Append($":artist=\"{author}\"");

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

//----分析完毕
var arguments = (Config.DEBUG_LOG ? " -v " : "") + inputArg + (metaArg.ToString() == "" ? "" : " -itags tool=" + metaArg.ToString()) + $" -new -- \"{outPath}\"";
var arguments = (Config.DEBUG_LOG ? " -v " : "") + inputArg + (metaArg.ToString() == "" ? "" : " -itags tool=" + metaArg) + $" -new -- \"{outPath}\"";
LogDebug("mp4box命令: {0}", arguments);
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, bool simplyMux = false)
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)
{
if (audioOnly && audioPath != "")
videoPath = "";
Expand All @@ -104,10 +105,11 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
desc = EscapeString(desc);
title = EscapeString(title);
episodeId = EscapeString(episodeId);
var url = $"https://www.bilibili.com/video/{bvid}/";

if (useMp4box)
{
return MuxByMp4box(videoPath, audioPath, outPath, desc, title, author, episodeId, pic, lang, subs, audioOnly, videoOnly, points);
return MuxByMp4box(url, videoPath, audioPath, outPath, desc, title, author, episodeId, pic, lang, subs, audioOnly, videoOnly, points);
}

if (outPath.Contains('/') && ! Directory.Exists(Path.GetDirectoryName(outPath)))
Expand Down Expand Up @@ -179,6 +181,7 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
argsBuilder.Append(metaArg);
if (!simplyMux) {
argsBuilder.Append($"-metadata title=\"{(episodeId == "" ? title : episodeId)}\" ");
argsBuilder.Append($"-metadata comment=\"{url}\" ");
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}\" ");
Expand Down
11 changes: 8 additions & 3 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
public static async Task<int> Main(params string[] args)
{
Console.CancelKeyPress += Console_CancelKeyPress;
ServicePointManager.DefaultConnectionLimit = 2048;

Check warning on line 71 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-linux-arm64

'ServicePointManager' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 71 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-win-x64-arm64

'ServicePointManager' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 71 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-mac-x64-arm64

'ServicePointManager' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 71 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-linux-x64

'ServicePointManager' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

var rootCommand = CommandLineInvoker.GetRootCommand(RunApp);
Command loginCommand = new(
Expand Down Expand Up @@ -244,7 +244,7 @@

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

if (string.IsNullOrEmpty(aidOri))
{
Expand Down Expand Up @@ -287,6 +287,11 @@
{
Log("发布时间: " + FormatTimeStamp(pubTime, "yyyy-MM-dd HH:mm:ss zzz"));
}
var bvid = vInfo.PagesInfo.FirstOrDefault()?.bvid;
if (!string.IsNullOrEmpty(bvid))
{
Log($"视频URL: https://www.bilibili.com/video/{bvid}/");
}
var mid = vInfo.PagesInfo.FirstOrDefault(p => !string.IsNullOrEmpty(p.ownerMid))?.ownerMid;
if (!string.IsNullOrEmpty(mid))
{
Expand Down Expand Up @@ -453,7 +458,7 @@
}

//调用解析
ParsedResult parsedResult = await ExtractTracksAsync(aidOri, p.aid, p.cid, p.epid, myOption.UseTvApi, myOption.UseIntlApi, myOption.UseAppApi, firstEncoding);

Check warning on line 461 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-linux-arm64

Possible null reference argument for parameter 'encoding' in 'Task<ParsedResult> Parser.ExtractTracksAsync(string aidOri, string aid, string cid, string epId, bool tvApi, bool intlApi, bool appApi, string encoding, string qn = "0")'.

Check warning on line 461 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-win-x64-arm64

Possible null reference argument for parameter 'encoding' in 'Task<ParsedResult> Parser.ExtractTracksAsync(string aidOri, string aid, string cid, string epId, bool tvApi, bool intlApi, bool appApi, string encoding, string qn = "0")'.

Check warning on line 461 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-mac-x64-arm64

Possible null reference argument for parameter 'encoding' in 'Task<ParsedResult> Parser.ExtractTracksAsync(string aidOri, string aid, string cid, string epId, bool tvApi, bool intlApi, bool appApi, string encoding, string qn = "0")'.

Check warning on line 461 in BBDown/Program.cs

View workflow job for this annotation

GitHub Actions / build-linux-x64

Possible null reference argument for parameter 'encoding' in 'Task<ParsedResult> Parser.ExtractTracksAsync(string aidOri, string aid, string cid, string epId, bool tvApi, bool intlApi, bool appApi, string encoding, string qn = "0")'.
List<AudioMaterial> audioMaterial = [];
if (!p.points.Any())
{
Expand Down Expand Up @@ -664,7 +669,7 @@
Log($"开始合并音视频{(subtitleInfo.Any() ? "和字幕" : "")}...");
if (myOption.AudioOnly)
savePath = savePath[..^4] + ".m4a";
int code = BBDownMuxer.MuxAV(myOption.UseMP4box, videoPath, audioPath, audioMaterial, savePath,
int code = BBDownMuxer.MuxAV(myOption.UseMP4box, p.bvid, videoPath, audioPath, audioMaterial, savePath,
desc,
title,
p.ownerName ?? "",
Expand Down Expand Up @@ -753,7 +758,7 @@
Log($"开始混流视频{(subtitleInfo.Any() ? "和字幕" : "")}...");
if (myOption.AudioOnly)
savePath = savePath[..^4] + ".m4a";
int code = BBDownMuxer.MuxAV(false, videoPath, "", audioMaterial, savePath,
int code = BBDownMuxer.MuxAV(false, p.bvid, videoPath, "", audioMaterial, savePath,
desc,
title,
p.ownerName ?? "",
Expand Down
Loading