当环境变量RE_KEEP_IMAGE_SEGMENTS=1时, 跳过字幕转换为PNG后删除原始文件的逻辑 (#625)

This commit is contained in:
nilaoda 2025-03-11 23:07:06 +08:00 committed by GitHub
parent 30499f5f87
commit 848545a0bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 8 deletions

View File

@ -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();

View File

@ -0,0 +1,22 @@
namespace N_m3u8DL_RE.Config;
/// <summary>
/// 通过配置环境变量来实现更细节地控制某些逻辑
/// </summary>
public static class EnvConfigKey
{
/// <summary>
/// 当此值为1时, 在图形字幕处理逻辑中PNG生成后不再删除m4s文件
/// </summary>
public const string ReKeepImageSegments = "RE_KEEP_IMAGE_SEGMENTS";
/// <summary>
/// 控制启用PipeMux时, 具体ffmpeg命令行
/// </summary>
public const string ReLivePipeOptions = "RE_LIVE_PIPE_OPTIONS";
/// <summary>
/// 控制启用PipeMux时, 非Windows环境下命名管道文件的生成目录
/// </summary>
public const string ReLivePipeTmpDir = "RE_LIVE_PIPE_TMP_DIR";
}

View File

@ -454,6 +454,8 @@ internal class SimpleDownloadManager
// 处理图形字幕
await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir);
var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments);
if (keepSegments != "1")
foreach (var item in files) File.Delete(item);
FileDic.Clear();
var index = 0;
@ -506,6 +508,8 @@ internal class SimpleDownloadManager
// 处理图形字幕
await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir);
var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments);
if (keepSegments != "1")
foreach (var item in files) File.Delete(item);
FileDic.Clear();
var index = 0;

View File

@ -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} ");
}