From 848545a0bc66a81587098da0eb972861b9fb8f5e Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 11 Mar 2025 23:07:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F`R?= =?UTF-8?q?E=5FKEEP=5FIMAGE=5FSEGMENTS=3D1`=E6=97=B6,=20=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E5=AD=97=E5=B9=95=E8=BD=AC=E6=8D=A2=E4=B8=BAPNG=E5=90=8E?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8E=9F=E5=A7=8B=E6=96=87=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20(#625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +- src/N_m3u8DL-RE/Config/EnvConfigKey.cs | 22 +++++++++++++++++++ .../DownloadManager/SimpleDownloadManager.cs | 8 +++++-- src/N_m3u8DL-RE/Util/PipeUtil.cs | 11 +++++----- 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/N_m3u8DL-RE/Config/EnvConfigKey.cs diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index 4bfed2d..13815b7 100644 --- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs +++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs @@ -17,7 +17,7 @@ namespace N_m3u8DL_RE.CommandLine; internal static partial class CommandInvoker { - public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20241216"; + public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20250311"; [GeneratedRegex("((best|worst)\\d*|all)")] private static partial Regex ForStrRegex(); diff --git a/src/N_m3u8DL-RE/Config/EnvConfigKey.cs b/src/N_m3u8DL-RE/Config/EnvConfigKey.cs new file mode 100644 index 0000000..c71ce94 --- /dev/null +++ b/src/N_m3u8DL-RE/Config/EnvConfigKey.cs @@ -0,0 +1,22 @@ +namespace N_m3u8DL_RE.Config; + +/// +/// 通过配置环境变量来实现更细节地控制某些逻辑 +/// +public static class EnvConfigKey +{ + /// + /// 当此值为1时, 在图形字幕处理逻辑中PNG生成后不再删除m4s文件 + /// + public const string ReKeepImageSegments = "RE_KEEP_IMAGE_SEGMENTS"; + + /// + /// 控制启用PipeMux时, 具体ffmpeg命令行 + /// + public const string ReLivePipeOptions = "RE_LIVE_PIPE_OPTIONS"; + + /// + /// 控制启用PipeMux时, 非Windows环境下命名管道文件的生成目录 + /// + public const string ReLivePipeTmpDir = "RE_LIVE_PIPE_TMP_DIR"; +} \ No newline at end of file diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index b9333eb..f4bbb8b 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -454,7 +454,9 @@ internal class SimpleDownloadManager // 处理图形字幕 await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir); - foreach (var item in files) File.Delete(item); + var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments); + if (keepSegments != "1") + foreach (var item in files) File.Delete(item); FileDic.Clear(); var index = 0; var path = Path.Combine(tmpDir, index.ToString(pad) + ".fix.vtt"); @@ -506,7 +508,9 @@ internal class SimpleDownloadManager // 处理图形字幕 await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir); - foreach (var item in files) File.Delete(item); + var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments); + if (keepSegments != "1") + foreach (var item in files) File.Delete(item); FileDic.Clear(); var index = 0; var path = Path.Combine(tmpDir, index.ToString(pad) + ".fix.vtt"); diff --git a/src/N_m3u8DL-RE/Util/PipeUtil.cs b/src/N_m3u8DL-RE/Util/PipeUtil.cs index 65a988f..06d119b 100644 --- a/src/N_m3u8DL-RE/Util/PipeUtil.cs +++ b/src/N_m3u8DL-RE/Util/PipeUtil.cs @@ -3,6 +3,7 @@ using Spectre.Console; using System.Diagnostics; using System.IO.Pipes; using System.Text; +using N_m3u8DL_RE.Config; namespace N_m3u8DL_RE.Util; @@ -43,11 +44,11 @@ internal static class PipeUtil public static bool StartPipeMux(string binary, string[] pipeNames, string outputPath) { - string dateString = DateTime.Now.ToString("o"); - StringBuilder command = new StringBuilder("-y -fflags +genpts -loglevel quiet "); + var dateString = DateTime.Now.ToString("o"); + var command = new StringBuilder("-y -fflags +genpts -loglevel quiet "); - string customDest = OtherUtil.GetEnvironmentVariable("RE_LIVE_PIPE_OPTIONS"); - string pipeDir = OtherUtil.GetEnvironmentVariable("RE_LIVE_PIPE_TMP_DIR", Path.GetTempPath()); + var customDest = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReLivePipeOptions); + var pipeDir = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReLivePipeTmpDir, Path.GetTempPath()); if (!string.IsNullOrEmpty(customDest)) { @@ -63,7 +64,7 @@ internal static class PipeUtil command.Append($" -i \"{Path.Combine(pipeDir, item)}\" "); } - for (int i = 0; i < pipeNames.Length; i++) + for (var i = 0; i < pipeNames.Length; i++) { command.Append($" -map {i} "); }